Created
May 25, 2016 07:23
-
-
Save quangtqag/f24ffb4a1208303de662d944505779db to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view, typically from a nib. | |
// Force view follow specific orientation | |
let value = UIInterfaceOrientation.LandscapeRight.rawValue | |
UIDevice.currentDevice().setValue(value, forKey: "orientation") | |
} | |
// This method was called first to ask about supported orientation | |
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask { | |
return [UIInterfaceOrientationMask.Landscape] | |
} | |
// This method was called second if view allow rotating | |
override func shouldAutorotate() -> Bool { | |
return true | |
} | |
} | |
// If view controller not inside navigation controller then no need to override these function | |
// Orientation of view based on orientation of navigation view | |
// So set orientation of navigation view base on top view | |
extension UINavigationController { | |
public override func shouldAutorotate() -> Bool { | |
return visibleViewController!.shouldAutorotate() | |
} | |
public override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask { | |
return (visibleViewController?.supportedInterfaceOrientations())! | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment