如何使屏幕仅垂直。 (UITabBarController/Swift)
Posted
技术标签:
【中文标题】如何使屏幕仅垂直。 (UITabBarController/Swift)【英文标题】:How to make the screen vertically only. (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 上垂直显示屏幕。
【问题讨论】:
希望这个问题对你有帮助:***.com/questions/28938660/… @MoayadAlkouz 谢谢。 【参考方案1】:我建议你创建一个扩展
extension UITabBarController
override open var supportedInterfaceOrientations: UIInterfaceOrientationMask
return .portrait
用法:
let tabbar = UITabBarController.init()
_ = tabbar.supportedInterfaceOrientations
或
tabbar.supportedInterfaceOrientations = .portrait
【讨论】:
我可以设置竖屏。但是,我遇到了一个新问题。我想创建另一个问题,因为对问题的解释会很长。谢谢你的建议。以上是关于如何使屏幕仅垂直。 (UITabBarController/Swift)的主要内容,如果未能解决你的问题,请参考以下文章
Android开发点滴 - 如何使按钮水平垂直居中且始终占据屏幕宽度一半
如何仅使用 CSS 使 HTML 列表水平显示而不是垂直显示?