ios - 强制更改 UINavigationController 方向

标签 ios swift uinavigationcontroller

如何在 viewWillAppear 时强制改变方向?

我只想要一个 navigationController 强制横向,其他 Controller 我想要纵向。

当我按下横向 Controller 时,它显示为纵向,但当我旋转手机时,它会锁定,如我想要的横向。

当 vieWillAppear 时,我该怎么做?有什么作用吗?

最佳答案

override func viewDidLoad() {
    super.viewDidLoad()
    let value = UIInterfaceOrientation.landscape.rawValue
    UIDevice.current.setValue(value, forKey: "orientation")
}

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
    return .landscape
}

override var shouldAutorotate: Bool {
    return true
}

关于ios - 强制更改 UINavigationController 方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51679325/

相关文章:

ios - Swift 3 - 基于按钮状态的 If else 语句

iphone - 为什么我的 iOS 分发签名身份被撤销?

ios - UICollectionViewUpdateItem 可以用来更新单个标签吗?

ios - 在 subview Controller 中显示导航栏

ios - 无法弹出 viewController

iphone - UIPopoverController 中的 UINavigationController : setting the title

iphone - UIImage 显示在具有指定字符串值的单元格中

ios - 具有 3 个 View Controller 页面的页面 View Controller

ios - 更新 firebase 实时数据库 swift 4 中的特定子项

swift - 更改对象的框架大小后更新自动布局