iOS8下,UIImagePickerController的popoverPresentationController为空,要怎么获取?

来源:互联网 发布:mac通过蓝牙传输文件 编辑:程序博客网 时间:2024/06/05 11:08

想popover一个UIImagePickerController,结果发现UIImagePickerController的popoverPresentationController为空,怎么办?

在iOS8中,需要设置UIImagePickerController的modalPresentationStyle,如下:

imagePickerController.modalPresentationStyle = UIModalPresentationPopover;

然后,就可以使用popoverPresentationController了。如下:

UIPopoverPresentationController *popPC = imagePickerController.popoverPresentationController;popPC.sourceView = imageView;popPC.sourceRect = imageView.bounds;[self presentViewController:imagePickerController animated:YES completion:nil];

注意:代码中sourceRect一定要使用bounds,而不能使用frame,不这么用的话,小心弹出的控制器的位置有问题。

0 0