1

I have a single window Mac OSX app. The user can click 'x' (windowShouldClose() fires) and then I will just order the window back (ie, not exit the app).

If I try to bring the app back by clicking it from the dock or via cmd-tab, it doesn't become active.

I'm assuming I need to explicitly make the window key/active when it's clicked from the doc.

If so, what's the message sent to the app once the user clicks on the app from the dock?

4

2 回答 2

0

您应该像这样从 NSWindowController 继承:

class MyWindowController: NSWindowController, NSWindowDelegate {

    func windowShouldClose(_ sender: NSWindow) -> Bool {
        NSApp.hide(nil)
        return false
    }
}

然后你只需要打开你的 Main(或任何你有的名字)故事板,选择 Window Controller 并将你的 MyWindowController 设置为它:

在此处输入图像描述

资源

于 2019-06-05T08:42:11.963 回答
-1

将这些方法添加到应用程序委托中:

- (BOOL) applicationShouldOpenUntitledFile: (NSApplication *) sender {
    return YES;
}

- (BOOL) applicationOpenUntitledFile: (NSApplication *) theApplication {
    // Reopen your window here
    return YES;
}
于 2012-08-28T14:06:57.153 回答