如何阻止特定的 UIViewcontroller 横向

How to block specific UIViewcontroller for landscape orientation

我正在尝试为我的应用程序中的某些特定 UIViewController 阻止 LandscapeRight 方向。但它不起作用。我的应用程序支持自动布局以及 "landscape right" 和 "Portrait" 方向。

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

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

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