我有一个应用程序,它有几个窗口定义为窗口组,其结构符合主场景中的应用程序:
WindowGroup("StandingsView") {
StandingsView()
.environmentObject(appServices)
}
.handlesExternalEvents(matching: Set(arrayLiteral: "StandingsView"))
appServices 需要一些时间来配置,所以我不想在启动时自动恢复窗口。我在用户选择有效、服务完全配置并且用户按下“开始”SwiftUI 按钮时创建窗口:
if let standingsURL = URL(string: "raceStratLiteApp://StandingsView") {
NSWorkspace.shared.open(standingsURL)
}
我尝试关闭 appDelegate 的 applicationShouldTerminate() 中的窗口。
我还尝试在 applicationShouldTerminate 中将 isRestorable 设置为 false:
func applicationShouldTerminate(_ sender: NSApplication) -> NSApplication.TerminateReply {
for window in NSApplication.shared.windows {
window.isRestorable = false
}
return .terminateNow
}
还有其他方法不恢复窗口吗?或者更好的是,能够以编程方式将其恢复为之前的大小等,但仅在用户指示“启动”时启动
TIA
@Asperi 在后面的评论中建议的代码解决方案:
func applicationDidFinishLaunching(_ notification: Notification) {
UserDefaults.standard.register(defaults: ["NSQuitAlwaysKeepsWindows" : false])
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)