【问题标题】:Set one particular viewcontroller to landscape mode in swift快速将一个特定的视图控制器设置为横向模式
【发布时间】:2015-12-31 09:08:54
【问题描述】:

我们如何使用 xib 快速将一个特定的视图控制器设置为横向模式?

func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
        let orientation: UIInterfaceOrientationMask =
        [UIInterfaceOrientationMask.Portrait, UIInterfaceOrientationMask.PortraitUpsideDown]
        return orientation
}

我正在使用上面的代码,但它似乎不起作用..

【问题讨论】:

    标签: ios swift landscape


    【解决方案1】:

    我很确定您不能通过使用情节提要来针对每个视图控制器进行具体说明。如果您按原样在代码中执行此操作,则需要为该函数指定 override 关键字。您还需要确保您的应用项目支持您希望为任何特定视图控制器支持的所有界面方向。

    【讨论】:

      【解决方案2】:

      您需要在项目目标中检查设备方向

      然后在纵向的所有viewControllers中添加

      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
      }
      

      最后在你要添加的横向 viweController 中

      override func shouldAutorotate() -> Bool {
          return true
      }
      
      override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
          return [UIInterfaceOrientationMask.Portrait, UIInterfaceOrientationMask.Landscape, UIInterfaceOrientationMask.LandscapeLeft, UIInterfaceOrientationMask.LandscapeRight, UIInterfaceOrientationMask.PortraitUpsideDown]
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-12-20
        相关资源
        最近更新 更多