Change the root view of UIHostingController in SwiftUI

前端 未结 5 919
情歌与酒
情歌与酒 2020-12-03 07:19

For a new SwiftUI iOS app, I do the following in the SceneDelegate

if let windowScene = scene as? UIWindowScene {
    let window =          


        
5条回答
  •  醉梦人生
    2020-12-03 08:03

    For some animation while changing the rootview use the below code in sceneDelegate:

        window.rootViewController = UIHostingController(rootView: HomeView())
    
        // A mask of options indicating how you want to perform the animations.
        let options: UIView.AnimationOptions = .transitionCrossDissolve
    
        // The duration of the transition animation, measured in seconds.
        let duration: TimeInterval = 0.3
    
        // Creates a transition animation.
        UIView.transition(with: window, duration: duration, options: options, animations: {}, completion:
        { completed in
            // maybe do something on completion here
        })
    

提交回复
热议问题