我是 SwiftUI 的新手,遇到了一个问题,我想在应用程序内部发生某个操作时更改根视图。
我使用时的处理SceneDelegate
方式如下
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
... // the code of initializing the window
observeOnChangeWindow()
}
func observeOnChangeWindow(){
NotificationCenter.default.addObserver(self, selector: #selector(self.performChangeWindow), name: Notification.Name(K.changeWindowNotificationName), object: nil)
}
@objc func performChangeWindow() {
self.window?.rootViewController = UIHostingController(rootView: SplashScreenView())
}
但是,我目前没有使用 SceneDelegate,因为我正在使用 WindowGroup 初始化应用程序
struct MyApp: App {
var body: some Scene {
WindowGroup {
SplashScreenView()
}
}
}
我的问题是:我现在如何使用 SceneDelegate 执行相同的操作?