美文网首页
淡入淡出切换window根视图

淡入淡出切换window根视图

作者: 番茄炒西红柿啊 | 来源:发表于2018-01-04 11:34 被阅读12次

    网上看到的,自己做下笔记,代码很明了,不做过多解释.

    - (void)restoreRootViewController:(UIViewController *)rootViewController
    {
        typedef void (^Animation)(void);
        UIWindow* window = self.window;
        
        rootViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
        Animation animation = ^{
            BOOL oldState = [UIView areAnimationsEnabled];
            [UIView setAnimationsEnabled:NO];
            window.rootViewController = rootViewController;
            [UIView setAnimationsEnabled:oldState];
        };
        
        [UIView transitionWithView:window
                          duration:0.5f
                           options:UIViewAnimationOptionTransitionCrossDissolve
                        animations:animation
                        completion:nil];
    }
    

    不过这里最好注意下,被替换掉的rootViewController是否释放,防止内存泄漏.

    相关文章

      网友评论

          本文标题:淡入淡出切换window根视图

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