如何使屏幕仅垂直。 (UITabBarController/Swift)

How to make the screen vertically only. (UITabBarController/Swift)

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

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

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

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 上垂直显示屏幕。

我建议你创建一个扩展程序

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

用法:

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

tabbar.supportedInterfaceOrientations = .portrait