I made an example project on how to do this: GitHub repo .
Although @Sidetalker's answer is correct, I think he lacks a bit of explanation.
Basically you create a custom class for UINavigationControllerand assign it UINavigationControllerto the Storyboard. In the user class, UINavigationControlleryou overrideuse the function shouldAutorotateand check if there is topViewController ViewController(the class of yours UIViewControllerin the Storyboard) the class on which you want to disable autorotation.
In user 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
}
source
share