如何在iOS 9和Swift的Popover中呈现UIImagePickerController

时间:2015-08-06 01:10:14

标签: ios swift ipad uiviewcontroller

我试图在带有iOS 9 beta 4和Swift的iPad上使用popover呈现照片库。首选方法是通过弹出窗口,但UIPopoverController现已弃用。显然它现在通过UIViewController完成,但没有文档,或者我可以找到的示例代码。任何帮助将不胜感激!

谢谢!

3 个答案:

答案 0 :(得分:8)

上述答案几乎正确,但必须在调用popoverPresentationController之前设置presentViewController()中的锚点:

let myPicker = UIImagePickerController()
myPicker.delegate = self
myPicker.sourceType = .PhotoLibrary
myPicker.modalPresentationStyle = .Popover

let ppc = myPicker.popoverPresentationController
ppc?.barButtonItem = sender as? UIBarButtonItem
ppc?.permittedArrowDirection = .Any

presentViewController(myPicker, animated: true, completion: nil)

答案 1 :(得分:2)

我还没有进入图像选择器响应的委托和处理,这篇文章的目的只是考虑使用UIImagePickerController而不使用已弃用的类和方法。

let myPicker = UIImagePickerController()
myPicker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary

myPicker.modalPresentationStyle = UIModalPresentationStyle.Popover

self.presentViewController(myPicker, animated: true, completion: nil)

let popper = myPicker.popoverPresentationController
// returns a UIPopoverPresentationController
popper?.barButtonItem = sender as? UIBarButtonItem

请在需要时纠正

答案 2 :(得分:0)

在调用imagepicker的函数中简单添加了imagePicker.delegate = self