我想知道如何關閉或退出我的應用程式?我也有一些用于關閉我的應用程式的代碼,但代碼看起來并不現代并且已更新為 SwiftUI,我們是否有一些新的更好的代碼?
import SwiftUI
@main
struct Work_Space_macOSApp: App {
var body: some Scene {
WindowGroup {
VStack {
Button("Close App") {
// Do we have more SwifUI-ish code for closing App?
NSApplication.shared.keyWindow?.close()
}
Button("Quit App") {
// How can I quit the app?
}
}
.frame(width: 200, height: 200)
}
}
}
uj5u.com熱心網友回復:
要終止應用程式:
NSApplication.shared.terminate(nil)
AppKit 中還有很多很多功能是 SwiftUI 不支持的。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/370554.html
上一篇:更改初始螢屏
