Skip to content

Instantly share code, notes, and snippets.

@ilandbt
Last active May 23, 2017 12:05
Show Gist options
  • Save ilandbt/7a43c38e56446fc338778b672749fee8 to your computer and use it in GitHub Desktop.
Save ilandbt/7a43c38e56446fc338778b672749fee8 to your computer and use it in GitHub Desktop.
disabling autorotate
class MainNavigationController: UINavigationController {
// autorotate by top viewController
override var shouldAutorotate: Bool {
if !viewControllers.isEmpty {
return self.topViewController!.shouldAutorotate
} else {
return true
}
}
// orientation by top viewController
override var supportedInterfaceOrientations: UIInterfaceOrientationMask{
if !viewControllers.isEmpty {
return self.topViewController!.supportedInterfaceOrientations
} else {
return self.supportedInterfaceOrientations
}
}
}
class ViewController: UIViewController {
// disable autoratation
override var shouldAutorotate : Bool {
return false
}
//only portrait allowed
override var supportedInterfaceOrientations : UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.portrait
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment