sazz sazz - 8 months ago 729
iOS Question

Force landscape mode in one ViewController using Swift

I am trying to force only one view in my application on landscape mode,
I am calling

override func shouldAutorotate() -> Bool {
return false

override func supportedInterfaceOrientations() -> Int {
return Int(UIInterfaceOrientationMask.LandscapeLeft.rawValue)

override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {
return UIInterfaceOrientation.LandscapeLeft

The view is launched in the portrait mode, and keep rotating when I change the device orientation.

The shouldAutorotate is never called.

Any help would be appreciated.


It may be useful for others, I found a way to force the view to launch in landscape mode:

Put this in the viewDidLoad():

let value = UIInterfaceOrientation.LandscapeLeft.rawValue
UIDevice.currentDevice().setValue(value, forKey: "orientation")


override func shouldAutorotate() -> Bool {
    return true