可以設(shè)置新的UIWindow
的優(yōu)先級
- (void)longPress:(UITapGestureRecognizer *)recognizer {
// 長按保存圖片至相冊
if (recognizer.state == UIGestureRecognizerStateBegan) {
// 關(guān)鍵代碼
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];
}
}