Skip to content

Instantly share code, notes, and snippets.

@onmyway133
Created August 25, 2014 09:09
Show Gist options
  • Save onmyway133/4fa6e80a5c42ed763f39 to your computer and use it in GitHub Desktop.
Save onmyway133/4fa6e80a5c42ed763f39 to your computer and use it in GitHub Desktop.
switchRootViewController
- (void)switchRootViewController:(UIViewController *)viewController
animated:(BOOL)animated
completion:(void (^)())completion
{
UIWindow *window = self.appDelegate.window;
if (animated) {
[UIView transitionWithView:window
duration:0.3
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^
{
BOOL oldState = [UIView areAnimationsEnabled];
[UIView setAnimationsEnabled:NO];
window.rootViewController = viewController;
[UIView setAnimationsEnabled:oldState];
} completion:^(BOOL finished) {
if (completion) completion();
}];
} else {
window.rootViewController = viewController;
if (completion) completion();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment