I am trying to present UIImagePickerController
in landscape mode for iPhone 7
and iPhone SE
(iPhone 7 Plus and iPad use popover). I create a sub class of UIImagePickerController :
class LandscapeUIImagePickerController: UIImagePickerController {
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .landscape
}
override var shouldAutorotate: Bool {
return true
}
override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
return .landscapeRight
}
and call it like this :
func importFromGallery(_ sender:UIButton) {
let imagePicker = LandscapeUIImagePickerController()
imagePicker.modalPresentationStyle = .popover
imagePicker.popoverPresentationController?.sourceView = sender
imagePicker.popoverPresentationController?.sourceRect = sender.bounds
imagePicker.popoverPresentationController?.permittedArrowDirections = .down
imagePicker.delegate = self
present(imagePicker, animated: true, completion: nil)
}
This custom class works when you check Portrait
option in Device Orientation :
but I don't want to check this option because it affects to other parts of app like keyboard's accessory view and input view. Is there any possible way to open UIImagePickerController without checking that option ? I unchecked Portrait , but app crashes with this error :
* Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and [PUUIAlbumListViewController shouldAutorotate] is returning YES' * First throw call stack:
I am fine with if image picker opens in portrait I have to disable Portrait option.