可以设置新的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];
}
}