Skip to content

Instantly share code, notes, and snippets.

@quangtqag
Created May 25, 2016 07:23
Show Gist options
  • Save quangtqag/f24ffb4a1208303de662d944505779db to your computer and use it in GitHub Desktop.
Save quangtqag/f24ffb4a1208303de662d944505779db to your computer and use it in GitHub Desktop.
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