简体   繁体   中英

Add a Launch Screen to the iOS App in Code in Swift (without Storyboard or Launchboard)

I created my views in code. The starting point is the didFinishLaunchWithOptions function in the Appdelegate class.

    window = UIWindow(frame: UIScreen.main.bounds)
    window?.makeKeyAndVisible() 
    let controller = ViewController() // create an instance of my ViewController and set it to the rootViewController
    window?.rootViewController = controller

I would like to add a launch screen that appears instantly when your app starts up. The launch screen should be quickly replaced with the first screen of the app, giving the impression that your app is fast and responsive. I found some answers that said it is not possible( Is there any way to code the LaunchScreen programmatically ). My idea was creating a new launchView and replace it through NSTimer. Isn't there any easier or alternative way ?

Thanks

This is not possible as such as the Launch Screen is not a regular View Controller and it cannot hold any logic. Any animations which are there in the App during startup are handled after the launch Screen has appeared and the animations are in the root view controller as in Twitter app. If you are completely against using launch Screens then an alternative would be make a view in IB and use its screenShot as a splashImage. There is no way as of now to make a launchScreen programatically or to add any logic to it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM