Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to present an UIImagePickerController in a Popover with iOS 9 and Swift

I'm trying to present the photo library, in a popover, on an iPad with iOS 9 beta 4 and Swift. The preferred way is through a popover, but UIPopoverController is now deprecated. Apparently it's now done through UIViewController, but there is no documentation, or sample code out there that I could find. Any help would be greatly appreciated!

Thank you!

like image 521
user3481651 Avatar asked Aug 06 '15 01:08

user3481651


1 Answers

The above answer is almost correct except that the anchor in the popoverPresentationController must be set prior to calling 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)
like image 161
Bianconeri Avatar answered Nov 15 '22 22:11

Bianconeri