因为Pad上的UIAlertController在UIAlertControllerStyleActionSheet模式时与手机端不同,Pad不会从底部弹出,而是需要在给定的视图位置弹出。
所以需要做一个配置:
1.定义一个View
@property (strong,nonatomic) UIView *showSaveSheetView;
2.实现控件的设定
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"保存到相册" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {}];
UIAlertAction* saveAction = [UIAlertAction actionWithTitle:@"保存" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * action) {
UIImageWriteToSavedPhotosAlbum(self.imageView.image, self, @selector(imageSavedToPhotosAlbum: didFinishSavingWithError: contextInfo:), nil);
}];
[alert addAction:cancelAction];
[alert addAction:saveAction];
[self presentViewController:alert animated:true completion:nil];
3.只需要在其后加入下段代码即可
UIPopoverPresentationController *popover = alert.popoverPresentationController;
if (popover) {
UIWindow *window = [UIApplication sharedApplication].keyWindow;
if (!self.showSaveSheetView) {
self.showSaveSheetView = [[UIView alloc] init];
[window addSubview:self.showSaveSheetView];
}
self.showSaveSheetView.center = window.center;
popover.sourceView = self.showSaveSheetView;
popover.sourceRect = self.showSaveSheetView.bounds;
popover.permittedArrowDirections = UIPopoverArrowDirectionAny;
}
记得在弹框消失的方法中销毁视图
- (void)dismiss {
[self.showSaveSheetView removeFromSuperview];
self.showSaveSheetView = nil;
}