gpt4 book ai didi

swift - OS X 应用程序 swift 2.2 上的关闭按钮事件

转载 作者:搜寻专家 更新时间:2023-10-30 22:06:13 26 4
gpt4 key购买 nike

我正在使用 swift 2.2 版创建一个 OSX 应用程序。当用户单击我的应用程序左上角的关闭按钮时,我需要执行一个方法,我现在是 Cocoa 编程的新手,这是单击关闭按钮时执行的事件(参见图像)。

Close button

我的目的是当我将我的应用程序保持在停靠栏上时,它在单击关闭按钮后未打开(单击关闭按钮后应用程序下方的黑点显示),但在这种情况下右键单击并强制退出它然后单击应用程序停靠它将重新打开正常。我认为通过在关闭按钮事件中提供以下给定代码可以解决我的问题。

NSApplication.sharedApplication().terminate(self)

最佳答案

func applicationShouldTerminateAfterLastWindowClosed(sender: NSApplication) -> Bool {
NSApplication.sharedApplication().terminate(self)
return true
}

在 appdeligate 内部为我工作。

对于 Swift 4.2

func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
NSApplication.shared.terminate(self)
return true
}

关于swift - OS X 应用程序 swift 2.2 上的关闭按钮事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41605937/

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