美文网首页
iOS 使AlertController在视图的最上面,将其添加

iOS 使AlertController在视图的最上面,将其添加

作者: LoveBe | 来源:发表于2020-07-23 09:57 被阅读0次

    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"获取相册提示" message:@"开启相册提示" preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    [alertController addAction:cancelAction];
    
    UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"去设置" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        // 直接跳转到对应的设置中
        NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
        if ([[UIApplication sharedApplication] canOpenURL:url]) {
            [[UIApplication sharedApplication] openURL:url];
        }
    }];
    [alertController addAction:sureAction];
    
    ///为了使alertController显示在图片上面,故添加在Window上
    UIWindow *alertWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    alertWindow.rootViewController = [UIViewController new];
    alertWindow.windowLevel = UIWindowLevelAlert + 1;
    [alertWindow makeKeyAndVisible];
    
    [alertWindow.rootViewController presentViewController:alertController animated:YES completion:nil];

    相关文章

      网友评论

          本文标题:iOS 使AlertController在视图的最上面,将其添加

          本文链接:https://www.haomeiwen.com/subject/qbsclktx.html