我正在尝试在iOS 9 beta 4和Swift的iPad上,通过一个弹出视图来展示相册库。推荐的方法是使用弹出视图,但是
谢谢!
UIPopoverController
现已弃用。显然现在是通过UIViewController
实现,但是我找不到任何文档或样本代码。非常感谢您的帮助!谢谢!
UIPopoverController
现已弃用。显然现在是通过UIViewController
实现,但是我找不到任何文档或样本代码。非常感谢您的帮助!上述答案几乎正确,唯一不同的是在调用presentViewController()
之前,必须先设置popoverPresentationController
中的anchor:
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)
这里我并没有涉及到委托和处理图像选择器的响应,本篇文章旨在探讨使用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
请纠正(译文)如有需要