pad彈出UIAlertControllerStyleActionSheet時,在iphone上運行正常,但在ipad上崩潰,解決代碼以下:iphone
UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:@"請選擇圖片" message:@"" preferredStyle:UIAlertControllerStyleActionSheet];spa
if (isiPad) {//判斷是否爲ipad圖片
UIPopoverPresentationController *popover = alertVc.popoverPresentationController;ip
if (popover) {it
popover.sourceView = view;//視圖中的某個viewio
popover.sourceRect = view.bounds;im
popover.permittedArrowDirections = UIPopoverArrowDirectionDown;//alertVC彈出的位置ipad
}animate
}di
UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
}];
UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"相冊" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
}];
UIAlertAction *action3 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
[alertVc dismissViewControllerAnimated:YES completion:nil];
}];
[alertVc addAction:action1];
[alertVc addAction:action2];
[alertVc addAction:action3];
[self presentViewController:alertVc animated:YES completion:nil];