Presenting UIViewController on launch in iOS 8

Guides | Reviews By 3 years ago

When you show a login screen or a walkthrough in your app, a common strategy is to present a view controller with no animation in your application:didFinishLaunchingWithOptions: method.

In iOS 8 this has caused some issues because the window’s root view controller can be seen for a split second before your presented view controller is seen, this is an Apple bug.

For the mean time, I have found a pretty easy hack that can be used to fix this:

UIViewController *viewController = [[UIViewController alloc] init];
[viewController.view setBackgroundColor:[UIColor greenColor]];

//  Temporary iOS8 fix for 'presentation lag' on launch
[self.window addSubview:viewController.view];

[self.window.rootViewController presentViewController:viewController animated:NO completion:nil];

How this works is that just before you present your view controller, you add it to the window hierarchy. Apple’s split second bug still occurs, but because the presented view controller is already part of the window it looks seamless.

  • Francisco Ochoa

    Hi ! thanks for sharing I have a question the UIViecontroller of the above example is the login controller?, or Home ViewController, thanks,

  • pilot34

    nice trick, thx!