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