iOS在View上显示AlertController

前提:

满足以下两个条件(可参考使用该方式

    1. 使用 [[[UIApplication sharedApplication] delegate] window] 弹出的View
    1. 在该View上使用并弹出AlertController

现象:

弹出的AlertController图层在View图层下面,遮挡住了AlertController操作

原理:

1.创建一个 ViewController 对象为 tempVc ;
2.将 tempVc.view 添加到需显示 AlertController 的 View 上 ;
3.用 presentViewController: animated: completion: 显示 ;

实现:

    UIAlertController *alvc = [UIAlertController alertControllerWithTitle:@"标题" message:nil preferredStyle:(UIAlertControllerStyleAlert)];
    UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:@"重试" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"回调方法 ----- kkkk");
    }];
    [alvc addAction:confirmAction];

    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"挂断" style:(UIAlertActionStyleDestructive) handler:^(UIAlertAction * _Nonnull action) {
         NSLog(@"回调方法 ----- kkkk");
    }];
    [alvc addAction:cancelAction];

    UIViewController *tempVc = [[UIViewController alloc] init];
    [self addSubview:tempVc.view];
    [tempVc presentViewController:alvc animated:YES completion:^{
        [tempVc.view removeFromSuperview];
    }];

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