给加在window上的蒙版,添加弹出框

给页面添加了蒙版,将蒙版view放在了window上

self.window = [UIApplication sharedApplication].keyWindow;

[self.window addSubview:self.view];

但是有要求点击蒙版上的一个按钮,需要弹出提示框。

如果写UIAlertController的话,弹出的提示框在蒙版下层,会被挡住。

//    UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"温馨提示"  message:@"请输入邀请码" preferredStyle:UIAlertControllerStyleAlert];

//    UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {

//    }];

//    [alert addAction:cancelAction];

//    UIViewController * rootViewController = [[[UIApplication sharedApplication] keyWindow] rootViewController];

//    [rootViewController presentViewController:alert animated:YES completion:^{

//    }];

然后查了一下发现:IOS8中,Apple将UIActionSheet和UIAlertView整合成一个接口UIAlertController。

原来的是一个view,展示在window视图之上。现在改成了controller,展示方式变成由当前的controller直接present出来。

所以,就用老方法,UIAlertView,是显示在window之上的,所以这样就把蒙版挡住提示框的问题解决了。


 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示"

                                                    message:@"请输入邀请码"

                                                   delegate:nil

                                          cancelButtonTitle:@"确定"

                                          otherButtonTitles:nil, nil];

    [alert show];

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

推荐阅读更多精彩内容