【问题标题】:Turn off rotation?关闭旋转?
【发布时间】:2017-01-23 12:08:19
【问题描述】:

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

我在风景中有我的观点,它必须在风景中,所以我这样做

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

而且这个用户不能改变旋转

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

问题是它不起作用。我在推动景观后,但我仍然可以旋转它。

【问题讨论】:

    标签: ios swift rotation swift3 orientation


    【解决方案1】:

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

    override var shouldAutorotate: Bool {
         return false
    }
    
    override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
         return UIInterfaceOrientationMask.landscapeLeft
    }
    

    【讨论】:

    • @patrikbelis 欢迎朋友 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-29
    • 1970-01-01
    • 1970-01-01
    • 2018-03-16
    • 1970-01-01
    • 2020-10-10
    • 2014-07-02
    相关资源
    最近更新 更多