gpt4 book ai didi

xcode - 全屏退出后模态 NSWindow 消失

转载 作者:行者123 更新时间:2023-11-28 09:19:38 28 4
gpt4 key购买 nike

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

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)


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

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

最佳答案

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);
}

}

}

关于xcode - 全屏退出后模态 NSWindow 消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25839765/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com