Hi, I'm adding steps:
First launch I set LoginAndRegisterContainerView
with navigationcontroller
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else { return }
let contentView = LoginAndRegisterContainerView()
//
let window = UIWindow(windowScene: windowScene)
let navigationView = UINavigationController(rootViewController: UIHostingController(rootView: contentView))
window.rootViewController = navigationView
self.window = window
window.makeKeyAndVisible()
}
Later in MyView I want to change rootViewController
DispatchQueue.main.async {
let vc = UIHostingController(rootView: Home())
let sceneDelegate = UIApplication.shared.connectedScenes.first?.delegate as! SceneDelegate
let window = sceneDelegate.window
window?.rootViewController = vc
UIView.transition(with: window!, duration: 0.4, options: .transitionFlipFromRight, animations: {}, completion:
{ completed in
// maybe do something on completion here
})
}
is it the right way?( at the end my view hierarchy looks like this: