ios - 关闭旋转?

标签 ios swift rotation swift3 orientation

试图关闭该用户无法改变方向..

我的观点是横向的,它必须是横向的,所以我是这样做的

    let value = UIInterfaceOrientation.landscapeLeft.rawValue
    UIDevice.current.setValue(value, forKey: "orientation")

此外,用户无法更改旋转

    private func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
         return UIInterfaceOrientationMask.landscapeLeft
    }
    private func shouldAutorotate() -> Bool {
        return false
    }

问题是它不工作。我在插入景观之后,但我仍然可以旋转它。

最佳答案

来自 swift 3 shouldAutorotatesupportedInterfaceOrientationsproperty而不是method,所以你需要这样添加。

override var shouldAutorotate: Bool {
     return false
}

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
     return UIInterfaceOrientationMask.landscapeLeft
}

关于ios - 关闭旋转?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41806016/

相关文章:

ios - 核心数据 : Segue to detail controller with newly created ManagedObject

ios - didRotateFromInterfaceOrientation 旋转时没有触发?

python - Pygame Sprite 旋转太快

iphone - 滚动到顶部时闪烁滚动指示器

ios - Swift ios 这是一个很好的解决方案而不是表格单元格

ios - iAd ADBannerView 在设备上显示有色

ios - 旋转后宽度和高度不正确

ios - 如何在 Swift 4 的 if let 语句中返回一个值?

ios - 我的模型对象是否应该负责下载它们自己的资源?

swift - 如何使用异步回调修改结构?