^Above does not have answer at all...Having issues disabling auto rotation for specific (not all) View Controllers that are inside a navigation controller. Similar questions do not address the ability to disable autorotation for specific view controllers but rather to disable autorotation in all of the view controllers inside of a navigation controller. My navigation controller contains some VCs that I would like to have autorotation and others that I do not want to autorotate. No existing questions answer this satisfactorily.
I made an example project on how to do this: GitHub repo.
While @Sidetalker's answer is correct I think it lacks a bit of explanation.
Basically you create a Custom Class for your UINavigationController and assign it to UINavigationController in Storyboard. In the custom UINavigationController class you override the shouldAutorotate function and check if the topViewController is ViewController(the class of your UIViewController in Storyboard) of the class on which you want to disable autorotate.
In custom UINavigationController:
override func shouldAutorotate() -> Bool {
if !viewControllers.isEmpty {
// Check if this ViewController is the one you want to disable roration on
if topViewController!.isKindOfClass(ViewController) {
// If true return false to disable it
return false
}
}
// Else normal rotation enabled
return true
}
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