【问题标题】:How to make the screen vertically only. (UITabBarController/Swift)如何使屏幕仅垂直。 (UITabBarController/Swift)
【发布时间】:2018-07-22 07:20:31
【问题描述】:

当我使用 UITabbarController 时,我想只显示纵向屏幕而不旋转屏幕。

当我不使用 UITabBarController 时,我不旋转屏幕,它处于横向视图。

因此,我为不使用 UITabBarController 的 ViewController 设置了以下内容。

override var shouldAutorotate: Bool {
    get {
        return true
    }
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
    get {
        return .landscapeRight
    }
}

在应用程序的规范中,我们进行以下设置。

enter image description here

我在故事板 1 中使用 UITabbarController。 enter image description here

我没有在故事板 2 中使用 UITabbarController。 enter image description here

我想创建一个应用程序来从情节提要 1 移动到情节提要 2。

我不知道如何仅在我使用 UITabBarController 的 ViewController 上垂直显示屏幕。

【问题讨论】:

标签: ios swift xcode uiviewcontroller uitabbarcontroller


【解决方案1】:

我建议你创建一个扩展

extension UITabBarController {
  override open var supportedInterfaceOrientations: UIInterfaceOrientationMask {
      return .portrait
  }
}

用法:

 let tabbar = UITabBarController.init()
  _ = tabbar.supportedInterfaceOrientations

tabbar.supportedInterfaceOrientations = .portrait

【讨论】:

  • 我可以设置竖屏。但是,我遇到了一个新问题。我想创建另一个问题,因为对问题的解释会很长。谢谢你的建议。
猜你喜欢
  • 2017-07-12
  • 2014-01-09
  • 1970-01-01
  • 2012-08-12
  • 2015-03-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-15
相关资源
最近更新 更多