【问题标题】:Modal NSWindow disappears after FullScreen exit全屏退出后模态NSWindow消失
【发布时间】:2014-09-15 01:47:50
【问题描述】:

我正在开发一个 OS X 应用程序,并且是 Swift 和 OS X 开发的新手。我有一个我想成为模态的窗口,有时会有很多内容要显示,所以我想让它进入全屏模式。窗口笔尖和下面的代码实现了这一点,但退出全屏模式会导致窗口消失。如果我转到另一个桌面并返回,则窗口又回来了。下面是我的应用委托代码。

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)


一切都是“推断的行为”
全屏是“主窗口”,我尝试了“辅助窗口”,但没有成功。
内存已“缓冲”。

这是基于文档的应用程序的辅助窗口。我错过了什么?谢谢。

【问题讨论】:

  • 我想这是因为使窗口全屏结束了模态窗口。
  • 不,模式窗口没有结束。在全屏模式下,模态窗口存在并按需要运行。退出全屏会导致模式窗口不再可见,但主窗口仍然无法接收输入,就像模式窗口存在时一样。切换到不同的 OS X 桌面并返回后,模态窗口会重新出现并且仍然具有模态行为。

标签: xcode macos swift


【解决方案1】:

1.覆盖NSWindowDelegate.windowDidExitFullScreen;

2.设置 NSWindow.Delegate;

3.在windowDidExitFullScreen中调用NSWindow.makeKeyAndOrderFront或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);
        }

    }   

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    • 2012-03-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多