我正在开发OS X应用程序,并且是Swift和OS X开发的新手。我有一个窗口,我想要模态,有时会有很多内容要显示,所以我想让它进入全屏模式。窗口笔尖和下面的代码实现了这一点,但是退出FullScreen模式会导致窗口消失。如果我去另一个桌面并返回,窗口又回来了。以下是我的应用代理代码。
import Cocoa
class AppDelegate: NSObject, NSApplicationDelegate {
let theApp: NSApplication = NSApplication.sharedApplication()
var fooController: FooController?
func applicationDidFinishLaunching(aNotification: NSNotification?) {
// Insert code here to initialize your application
}
@IBAction func sessionFoo(sender: AnyObject) {
if fooController == nil {
fooController = FooController(windowNibName: "FooWindow")
}
// This works when it returns from FullScreen but isn't modal
// fooController!.showWindow(self)
// This is modal but the window disappears when returning from FullScreen
theApp.runModalForWindow(fooController!.window)
}
}
在窗口的属性检查器中:
检查以下内容:
Shadow
Close
Resize
Restorable
Deferred (for Memory)
一切都是"推断行为"
全屏是"主窗口",我试过"辅助窗口"没有运气。
记忆是"缓冲"。
这是基于文档的应用程序的辅助窗口。我错过了什么?感谢。
答案 0 :(得分:0)
1.overrides NSWindowDelegate.windowDidExitFullScreen;
2.设置NSWindow.Delegate;
3.call NSWindow.makeKeyAndOrderFront或NSWindow.OrderFront在windowDidExitFullScreen中;
public class tbWindowDelegate : NSWindowDelegate
{
public EventHandler WindowFullScreenDidExit;
public override void DidExitFullScreen(NSNotification notification)
{
if (WindowFullScreenDidExit != null)
WindowFullScreenDidExit(notification, EventArgs.Empty);
}
}
public class tbWindow : NSWindow
{
protected bool mRunModal = false;
protected tbWindowDelegate mDelegate = null;
public tbWindow() : base()
{
this.InitEvent();
}
private void InitEvent()
{
this.mDelegate = new tbWindowDelegate();
this.mDelegate.WindowFullScreenDidExit = this.OnWindowFullScreenDidExit;
this.Delegate = this.mDelegate;
}
protected virtual void OnWindowFullScreenDidExit(object sender, EventArgs e)
{
if (this.mRunModal)
{
//this.MakeKeyAndOrderFront(this);
this.OrderFront(this);
}
}
}