简体   繁体   中英

iOS - Show splash screen every time app opens

I know this is bad UX, however a client has requested that I display a splash screen for 2 seconds every time the user opens the app.

I have tried implementing this through the AppDelegate by:

  • Creating an instance variable of the splash screens view controller in the application:didFinishLaunchingWithOptions: method, and settings the alpha of its view to 0.

  • Then in applicationWillEnterForeground: I set the alpha to 1 in the hope that the splash screen will show every time the user opens the app, then set the alpha back to 0 after 2 seconds.

Now, this does work, however not properly. When the app opens the main UI is shown momentarily then the splash screen is shown.

Of course this is not what is intended as the splash screen should be shown before the main UI.

I am trying to persuade the client to do away with this, however does anyone know how it can be implemented properly (in case they are totally adamant that they want it)?

From application:didFinishLaunchingWithOptions:

_tabBarController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"TabBarController"];
[[self window] setRootViewController:_tabBarController];
[_tabBarController setDelegate:self];


_loadingViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoadingView"];
[[_loadingViewController view] setAlpha:0.0f];
[_loadingViewController willMoveToParentViewController:_tabBarController];
[_tabBarController addChildViewController:_loadingViewController];
[_loadingViewController didMoveToParentViewController:_tabBarController];
[[_tabBarController view] addSubview:_loadingViewController.view];

From applicationWillEnterForeground:

[[_loadingViewController view] setAlpha:1.0f];

[self performSelector:@selector(removeLoadingView) withObject:nil afterDelay:2.0];

This is a workaround but you can always try :

Put a UIImageView on the root view controller. (or create a new one with the splash screen image) Once the real splash is removed, this view will displayed then you can remove it after with the effect of your choice.

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