0

I am making an app that allows the user to open the photo gallery to change a picture in an image view. Whenever I lock the orientation to landscape mode, to avoid gross constraints and the app overall shoving everything I love off the screen, the photo gallery tries to open in portrait mode. To fix this I made a new class called UIImagePickerController+SupportedOrientations and added

extension UIImagePickerController
{
    public override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
        return .Landscape
    }
    override public func shouldAutorotate() -> Bool { return false }
}

to hopefully stop this. Now it opens in landscape mode whenever I use the app without locking it, but if I lock it I get the following error

terminating with uncaught exception of type NSException
zach2161
  • 113
  • 11

1 Answers1

-1

It absolutely supports landscape mode. Put this extension somewhere. Best in a file named UIImagePickerController+SupportedOrientations.swift

extension UIImagePickerController
{
    public override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
        return .Landscape
    }
}

This makes all UIImagePickerControllers in your app landscape. You can also subclass it and override this method to make only a subclass landscape-able:

class LandscapePickerController: UIImagePickerController
{
    public override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
        return .Landscape
    }
}

Finally, to support Landscape orientations you can return

return [.Landscape]
A K M Saleh Sultan
  • 2,403
  • 2
  • 22
  • 28
  • -1 This solution is a copy of the answer provided in: Use UIImagePickerController in landscape mode in Swift 2.0 (http://stackoverflow.com/questions/33058691/use-uiimagepickercontroller-in-landscape-mode-in-swift-2-0) – David Feb 28 '17 at 16:42