At this time I am halfway to keeping ViewControllerA in portrait mode. To do this, I am using preferredInterfaceOrientationForPresentation
This ensures that ViewControllerA, when I push to it, will be in portrait mode. However, if I push from ViewControllerA to ViewControllerB, switch to landscape mode in ViewControllerB, and then dismiss back to ViewControllerA, ViewControllerA can be presented in landscape mode. My desire is to continue multiple orientation support of ViewControllerB, but force ViewControllerA to autorotate to portrait.
Also, for some reason shouldAutorotate does not appear to be getting called in ViewControllerA. Perhaps addressing this could fix the entire issue?
UINavigationController+Orientation.h Category
@interface UINavigationController (Orientation)
- (BOOL)shouldAutorotate;
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation;
@end
UINavigationController+Orientation.m Category
-(BOOL)shouldAutorotate {
return [[self.viewControllers lastObject] shouldAutorotate];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
@end
ViewControllerA.m
- (BOOL)shouldAutorotate {
return YES;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}