前提:
满足以下两个条件(可参考使用该方式)
- 使用 [[[UIApplication sharedApplication] delegate] window] 弹出的View
- 在该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];
}];