// 淡入淡出更换rootViewController
- (void)restoreRootViewController:(UIViewController *)rootViewController
{
typedef void (^Animation)(void);
AppDelegate *appdelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
UIWindow* window = appdelegate.window;
rootViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
Animation animation = ^{
BOOL oldState = [UIView areAnimationsEnabled];
[UIView setAnimationsEnabled:NO];
[UIApplication sharedApplication].keyWindow.rootViewController = rootViewController;
[UIView setAnimationsEnabled:oldState];
};
[UIView transitionWithView:window
duration:0.5f
options:UIViewAnimationOptionTransitionCrossDissolve
animations:animation
completion:nil];
}
至于为什么不用 keyWindow 请参考http://www.jianshu.com/p/ae84cd31d8f0,
小心使得万年船,哈哈.
网友评论