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.
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.landscapeLeft.rawValue, forKey: "orientation")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With