4

I have an app where some of the screens should be in portrait mode and some of them in landscape. For example, main menu is portrait and there is a camera button. The camera should be available only in landscape. I am using Storyboard and NavigationController. Where and what should I do to achieve this?

I already tried to include

shouldAutorotate() -> Bool {return false or return true} 

neither worked. I have set the

supportedInterfaceOrientation 

for every viewcontroller I have. Nothing helped. I need a function what I can call to force the screen into landscape/portrait mode.

Umit Kaya
  • 5,771
  • 3
  • 38
  • 52
MegaX
  • 596
  • 2
  • 11
  • 23

1 Answers1

15

Use this line of code in your ViewDidLoad (or wherever you want).

Swift 1 UIDevice.currentDevice().setValue(UIInterfaceOrientation.LandscapeLeft.rawValue, forKey: "orientation")

Tested 3 minutes ago in Swift 1.2 Xcode 6.3

Swift 3 (Thanks to Fa.Shapouri)

UIDevice.current.setValue(UIInterfaceOrientation.landscapeLe‌​ft.rawValue, forKey: "orientation")
gutenmorgenuhu
  • 2,312
  • 1
  • 19
  • 33