使用xcode 12.3和swift 5.3与SwiftUI App生命周期构建一个macOS应用程序,什么是最好的方式来访问和更改的外观和行为NSWindow?
编辑:我真正追求的是NSWindow实例。
我添加了一个AppDelegate,但据我了解它NSWindow很可能是nil,因此无法修改,只需在此处创建一个类似于AppKit App Delegate生命周期方法的方法,就会在启动时出现两个窗口。
一种解决方案是防止默认窗口出现,并将其全部留给applicationDidFinishLaunching方法,但不确定这是可能的或明智的。
该WindowStyle协议看起来是一种可能的解决方案,但不确定CustomWindowStyle在此阶段如何最好地利用它,以及是否提供对NSWindow实例的访问以进行细粒度控制。
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ aNotification: Notification) {
// In AppKit simply create the NSWindow and modify style.
// In SwiftUI creating an NSWindow and styling results in 2 windows,
// one styled and the other default.
}
} …Run Code Online (Sandbox Code Playgroud)