如何单击左上角的红点以编程方式终止MacOS应用?

问题描述 投票:1回答:1

早安!

默认情况下,当我们单击窗口应用程序的左上角红点时,窗口关闭,但应用程序未关闭,菜单栏始终显示在顶部。

我想通过代码实现的是,当我们单击红点时终止(关闭)该应用程序...通过这样做,菜单栏将消失,因此该应用程序已终止。

感谢您的帮助。

macos swiftui dot terminate
1个回答
1
投票

在您的应用程序委托中添加以下回调

class AppDelegate: NSObject, NSApplicationDelegate {

    //... other methods here

    func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
        return true
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.