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)]];
    });

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容