// 淡入淡出更換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.reibang.com/p/ae84cd31d8f0,
小心使得萬年船,哈哈.