美文网首页
动画 更换 主Window 的 rootViewControll

动画 更换 主Window 的 rootViewControll

作者: 清河湾 | 来源:发表于2017-08-30 18:41 被阅读114次

    // 淡入淡出更换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,
    小心使得万年船,哈哈.

    相关文章

      网友评论

          本文标题:动画 更换 主Window 的 rootViewControll

          本文链接:https://www.haomeiwen.com/subject/ubuxjxtx.html