iOS如何在UIWindow上弹出UIAlertController提示框

可以设置新的UIWindow的优先级

- (void)longPress:(UITapGestureRecognizer *)recognizer {
//    长按保存图片至相册
    if (recognizer.state == UIGestureRecognizerStateBegan) {
       // 关键代码
        UIImage *image = self.fromTheImageView.image;
        UIWindow *alertWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
        alertWindow.rootViewController = [UIViewController new];
        alertWindow.windowLevel = UIWindowLevelAlert + 1;
        [alertWindow makeKeyAndVisible];
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"保存图片" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
        UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
//                保存图片至相册
                [PHAssetChangeRequest creationRequestForAssetFromImage:image];
            } completionHandler:^(BOOL success, NSError * _Nullable error) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    if (success) {
                        [TipUtils showToast:self message:@"图片成功保存到相册"];
//                        [self dismiss];
                    }
                    NSLog(@"%@",success ? @"保存成功" : @"保存失败");
                });
            }];
        }];
        UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
        [alert addAction:action];
        [alert addAction:cancel];
        [alertWindow.rootViewController presentViewController:alert animated:YES completion:nil];
    }
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容