UIWindow

2018年10月18日

  1. 常用方法
 [[UIApplication sharedApplication] delegate].window.rootViewController = nil;
    CustomMyViewController *custom = [[CustomMyViewController alloc]init];
    custom.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [[UIApplication sharedApplication] delegate].window.rootViewController = custom;

或者

loginViewController * loginVC = [[loginViewController alloc] init];
    UIViewController * oldRootVC = [[[UIApplication sharedApplication] delegate] window].rootViewController;
    while ([[[UIApplication sharedApplication] delegate] window].subviews.lastObject) {
        [[[[UIApplication sharedApplication] delegate] window].subviews.lastObject removeFromSuperview];
    }
    [[[UIApplication sharedApplication] delegate] window].rootViewController = loginVC;
    //删除老的
    oldRootVC = nil;

2017年1月11日
一.keyWindow与delegate中Window的区别

1.测试

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self testKeyWindowAndDelegateWindow];
}
 - (void)viewDidAppear:(BOOL)animated
{
    [self testKeyWindowAndDelegateWindow];
}

- (void)testKeyWindowAndDelegateWindow
{
//    NSLog(@"#######%s",__FUNCTION__);
    NSLog(@"%@", [UIApplication sharedApplication].keyWindow);
    NSLog(@"%@", [[[UIApplication sharedApplication] delegate] window]);
}

结果:基本一样,除了页面刚刚加载的时候keywindow为空


UIWindow_第1张图片
image.png

如果您发现本文对你有所帮助,如果您认为其他人也可能受益,请把它分享出去。

你可能感兴趣的:(UIWindow)