UIWindow的特别注意

1.新创建的UIWindow不需要添加到任何父控件上就能显示出来(需保证创建的window不销毁,用属性强引用)
2.window有级别:UIWindowLevelNormal < UIWindowLevelStatusBar < UIWindowLevelAlert
级别越高的window越显示在上面
级别相等的window,后面显示的window显示在上面
3.窗口要不设根控制器会报错,可以采用延时来避免报错
报错:
Application windows are expected to have a root view controller at the end of application launch
延时:

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        self.topWindow = [[UIWindow alloc] init];
//        self.topWindow.frame = application.statusBarFrame;
        self.topWindow.frame = CGRectMake(280, 500, 80, 80);
        self.topWindow.backgroundColor = [UIColor redColor];
        self.topWindow.windowLevel = UIWindowLevelAlert;
        self.topWindow.hidden = NO;
        [self.topWindow addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(click)]];
    });

可能的应用场景:电商的购物车(全程一直显示在最外层)

你可能感兴趣的:(UIWindow的特别注意)