我有 3 个UIViewControllers
层次UINavigationController
结构。
如何仅为其中最后一个启用横向模式?(或在第 1 和第 2 中阻止景观)。
(我通过按 1st > 2nd > 3rd 打开它们)
我尝试用这些方法覆盖 UINavigationController:
-(NSUInteger)supportedInterfaceOrientations {
UIViewController *top = self.topViewController;
if ([top isMemberOfClass:[PictureViewController class]]) {
return UIInterfaceOrientationPortrait | UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight;
} else {
return UIInterfaceOrientationPortrait;
}
}
-(BOOL)shouldAutorotate {
UIViewController *top = (UIViewController*) self.topViewController;
if ([top isMemberOfClass:[PictureViewController class]]) {
return YES;
} else {
return NO;
}
}
PictureViewController
是第 3 位UIViewController
。为它shouldAutorotate
返回并返回YES
supportedInterfaceOrientations
UIInterfaceOrientationPortrait | UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight;
但未启用横向。