How can I delay splash launch screen programmatically in Swift Xcode iOS

后端 未结 6 1803
后悔当初
后悔当初 2021-01-31 19:01

I have put an image in imageView in LaunchStoreyboard. How can I delay the time of image programmatically?

Here is the Lau

6条回答
  •  春和景丽
    2021-01-31 19:54

    Swift 5.x, iOS 13.x.x

    Modifying the following function in the AppDelegate class does not work in Swift 5.x/iOS 13.x.x.

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        return true
    }
    

    Instead, you will have to modify the scene function in SceneDelegate class as following. It will delay the LaunchSceen for 3 seconds.

    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    
        window?.rootViewController = UIStoryboard(name: "LaunchScreen", bundle: nil).instantiateInitialViewController()
        window?.makeKeyAndVisible()
    
        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 3) {
            self.window?.rootViewController = UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController()
        }
    
        guard let _ = (scene as? UIWindowScene) else { return }
    }
    

    The window variable should already be there in SceneDelegate class like the following.

    var window: UIWindow?
    

提交回复
热议问题