【问题标题】:How to disable autorotation for UINavigationController's root view controller?如何禁用 UINavigationController 根视图控制器的自动旋转?
【发布时间】:2016-07-05 02:27:27
【问题描述】:

我需要在我的应用程序中支持所有界面方向掩码。 一些视图控制器不应该自动旋转(它只支持纵向),但应用程序仍然需要支持所有方向。 Expected result

我尝试在 UINavigationController 中设置 shouldAutorotate = true; supportedInterfaceOrientations = All,在根视图控制器中设置 shouldAutorotate = false; supportedInterfaceOrientations = Portrait。但它不起作用。

【问题讨论】:

    标签: ios objective-c swift user-interface


    【解决方案1】:

    您可以在仅支持纵向模式的 viewController 中使用它

    override func shouldAutorotate() -> Bool {
        if (UIDevice.currentDevice().orientation == UIDeviceOrientation.Portrait ||
            UIDevice.currentDevice().orientation == UIDeviceOrientation.PortraitUpsideDown ||
            UIDevice.currentDevice().orientation == UIDeviceOrientation.Unknown) {
                return true;
        } else {
            return false;
        }
    }
    
    override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
        return UIInterfaceOrientationMask.Portrait
    }
    

    【讨论】:

      【解决方案2】:

      由于每个视图控制器都支持不同的方向,您可以这样做:

      1) 在项目的常规选项卡中,选择您需要应用程序支持的方向。 for reference click here

      2) 现在,在每个视图控制器中添加以下代码:

         - (UIInterfaceOrientationMask) supportedInterfaceOrientations {
      
          return UIInterfaceOrientationMaskPortrait;
      }
      

      在此方法中为特定视图控制器返回您想要的任何方向。

      【讨论】:

        【解决方案3】:

        您必须按照以下步骤设置 Xcode 设置以处理旋转:

        项目>目标>常规>部署信息>设备方向>(复选标记)纵向

        希望对你有帮助。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2013-10-12
          • 2016-03-11
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多