iOS在View上顯示AlertController

前提:

滿足以下兩個條件(可參考使用該方式

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

現(xiàn)象:

彈出的AlertController圖層在View圖層下面,遮擋住了AlertController操作

原理:

1.創(chuàng)建一個 ViewController 對象為 tempVc ;
2.將 tempVc.view 添加到需顯示 AlertController 的 View 上 ;
3.用 presentViewController: animated: completion: 顯示 ;

實現(xiàn):

    UIAlertController *alvc = [UIAlertController alertControllerWithTitle:@"標(biāo)題" message:nil preferredStyle:(UIAlertControllerStyleAlert)];
    UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:@"重試" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"回調(diào)方法 ----- kkkk");
    }];
    [alvc addAction:confirmAction];

    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"掛斷" style:(UIAlertActionStyleDestructive) handler:^(UIAlertAction * _Nonnull action) {
         NSLog(@"回調(diào)方法 ----- kkkk");
    }];
    [alvc addAction:cancelAction];

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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容