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,471
  • 2
  • 37
  • 51
MegaX
  • 566
  • 1
  • 10
  • 22

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,257
  • 1
  • 18
  • 33