How to introduce UIImagePickerController in Popover with iOS 9 and Swift

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

Thanks!

+6
source share
2 answers

The above answer is almost correct, except that the anchor in the popoverPresentationController must be set before the presentViewController() called:

 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) 
+6
source

I was not involved in delegating and processing responses to the image picker here, the purpose of this post was simply to consider using UIImagePickerController without resorting to obsolete classes and methods.

 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 

Please correct if necessary.

+2
source

All Articles