如何在NavigationController层次结构中的单个ViewController中启用横向模式

时间:2013-08-27 11:47:46

标签: ios uinavigationcontroller

我在UIViewControllers层次结构中有3个UINavigationController

如何仅为最后一个启用横向模式? (或在第1和第2区阻挡景观。)

(我通过推送第一个>第二个>第三个来打开它们)

我尝试用这些方法覆盖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 UIViewControllershouldAutorotate为其返回YESsupportedInterfaceOrientations返回UIInterfaceOrientationPortrait | UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight;

但未启用横向。

1 个答案:

答案 0 :(得分:0)

你确定这次检查

if ([top isMemberOfClass:[PictureViewController class]]) {
    return UIInterfaceOrientationPortrait | UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight;
} else {
    return UIInterfaceOrientationPortrait;
}

工作正常吗?

在视图控制器和导航控制器中尝试覆盖方法 - (BOOL)shouldAutorotate和 - (NSUInteger)supportedInterfaceOrientations仅调用此方法。

-(NSUInteger)supportedInterfaceOrientations {
   return [self.topViewController supportedInterfaceOrientations];
 }

 -(BOOL)shouldAutorotate {
     return [self.topViewController shouldAutorotate];
 }

正如注意用户Pavan Saberjack,检查项目plist中支持的方向。