Created
August 25, 2014 09:09
-
-
Save onmyway133/4fa6e80a5c42ed763f39 to your computer and use it in GitHub Desktop.
switchRootViewController
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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