Swap rootViewController with animation?

I'm trying to swap out the rootViewController in my appDelegate with an animation and it is just flashing to the new viewController without any animation.


-(void)showRootController:(UIViewController *)controller {
    [UIView transitionWithView:self.window duration:0.5 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
        self.window.rootViewController = controller;
        [self.window makeKeyAndVisible];
    }
    completion:nil];
}


How can I do this with an animation? (Testing on an iPhone 5s with iOS 8)

I'd recommend keeping the rootViewController the same. Make it a UIPageViewController or some custom container view controller so that you can have it explicitly manage swapping between child view controllers with whatever animation you like animations. Changing rootViewControllers can be flaky.

This is an excerpt from DZAppDelegate which achieves swapping rootViewControllers on a UIWindow


- (void)setRootViewController:(UIViewController *)viewController
  withTransition:(UIViewAnimationOptions)transition
  duration:(NSTimeInterval)duration
  completion:(void (^)(BOOL finished))completion
{

  UIViewController *oldViewController = self.window.rootViewController;

  [UIView transitionFromView:oldViewController.view toView:viewController.view duration:duration options:(UIViewAnimationOptions)(transition|UIViewAnimationOptionAllowAnimatedContent|UIViewAnimationOptionLayoutSubviews) completion:^(BOOL finished) {

  self.window.rootViewController = viewController;

  if (completion)
  {
      completion(finished);
  }

  }];

}

If other view controllers are on the stack of the old view controller, their memory might not be freed which leads to leaks.

Swap rootViewController with animation?
 
 
Q