iOS: how to delay the launch screen?

江枫思渺然 提交于 2019-12-30 04:06:47

问题


When launch an app, the LaunchScreen.xib is removed as soon as all the assets are initialized.

I want to make the launch screen stay for at least 1 sec.

Is there a way to achieve this?

Thank you!


回答1:


You can create a view controller that uses the LaunchScreen storyboard, present it (not animated) on applicationDidFinishLaunching or applicationWillFinishLaunching, and dismiss it whenever you want.

Keep in mind this is discouraged by Apple because it gives the impression that your app takes a lot longer to launch, which is bad user experience and might cause some of your users to delete your app.




回答2:


Swift 4 Update

Just write one line of code Thread.sleep(forTimeInterval: 3.0) in the method of didfinishLauching.... in appdelegate class.

Example

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



回答3:


Never sleep on the main thread. Doing this could actually cause iOS to kill your app for taking too long to start up




回答4:


Thought I chip in my thoughts on this, I wanted to write in comments but it won't allow many lines. I believe many apps developer want to do this (delay the launch screen) is because they want to build a brand presence of the apps/games for their company.

Having said that, launch screen is NOT designed for that, as Rick Maddy explained in the comment section in one of the other answers. Launch screen's purpose is to make users feel the app is instantly running by showing the empty UI while the actual data is loading at the back (willAppear and so on).

So to achieve what many developers want, while being in-line with Apple's HIG, what you can do is:

  1. Display UI template in the launchscreen as intended by Apple HIG.
  2. Upon main screen load, load up another VC that shows "intro" of your brand. Make sure this runs only ONCE (a simple flag in NSUserDefaults should do the trick).
  3. Users should be allowed to skip this if it is a long "intro".

The same "intro" VC should be available to user by tapping on a "View Intro" button somewhere (maybe in about page).




回答5:


If you want to go with simple, you can use NSThread:

[NSThread sleepForTimeInterval:(NSTimeInterval)];

You can put this code into the first line of applicationDidFinishLaunching method.

For example, display default.png for 1.0 seconds.

- (void) applicationDidFinishLaunching:(UIApplication*)application
{
   [NSThread sleepForTimeInterval:1.0];
}

It will stop splash screen for 1.0 seconds.



来源:https://stackoverflow.com/questions/35028449/ios-how-to-delay-the-launch-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!