Xcode 模式窗口在全屏退出后消失
我正在开发一个OSX应用程序,我是Swift和OSX开发的新手。我有一个窗口,我想成为模态,有时会有很多内容显示,所以我想让它进入全屏模式。窗口笔尖和下面的代码完成了这一点,但退出全屏模式会导致窗口消失。如果我转到另一个桌面并返回,窗口将返回。下面是我的应用程序代理代码Xcode 模式窗口在全屏退出后消失,xcode,macos,swift,Xcode,Macos,Swift,我正在开发一个OSX应用程序,我是Swift和OSX开发的新手。我有一个窗口,我想成为模态,有时会有很多内容显示,所以我想让它进入全屏模式。窗口笔尖和下面的代码完成了这一点,但退出全屏模式会导致窗口消失。如果我转到另一个桌面并返回,窗口将返回。下面是我的应用程序代理代码 import Cocoa class AppDelegate: NSObject, NSApplicationDelegate { let theApp: NSApplication = NSApplication.s
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)
}
}
在窗口的属性检查器中:
检查以下各项:
一切都是推断的行为
全屏是主窗口,我尝试了辅助窗口,但运气不好。
内存被缓冲
这是基于文档的应用程序的辅助窗口。我错过了什么?谢谢。1.windowdelegate.windowDidExitFullScreen 2.设置NSWindow.Delegate 3.在WindowDidExitFull屏幕中调用NSWindow.MakeKeyandDerfront或NSWindow.OrderFront
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);
}
}
}
我想这是因为使一个窗口全屏显示结束了模式窗口。不,模式窗口没有结束。在全屏显示中,模式窗口显示并按需要运行。退出全屏会导致模式窗口不再可见,但主窗口仍无法像模式窗口出现时那样接收输入。切换到不同的OSX桌面并返回后,模式窗口将重新出现,并且仍然具有模式行为。
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);
}
}
}