如何阻止特定的UIViewcontroller进行横向定位

时间:2015-09-08 15:10:07

标签: ios objective-c iphone uiviewcontroller

我正在尝试阻止我的应用中某些特定UIViewControllers的LandscapeRight方向。但它不起作用。我的应用程序支持自动布局以及"风景正确"和#34;肖像"取向。

这是我正在尝试的代码。我错过了什么吗?

-   (BOOL)shouldAutorotate {
    return YES;
  }
-   (NSUInteger)supportedInterfaceOrientations {
    return (UIInterfaceOrientationMaskPortrait);
} 

1 个答案:

答案 0 :(得分:1)

顶级视图控制器负责应用程序方向。您在导航界面中。因此,UINavigationController,而不是您的孩子UIViewController,是顶级的,因此咨询应用方向。您的supportedInterfaceOrientations甚至从未被调用过。使用UINavigationControllerDelegate方法navigationControllerSupportedInterfaceOrientations