【问题标题】:iOS Swift UIViewController RotationiOS Swift UIViewController 旋转
【发布时间】:2018-12-03 02:37:29
【问题描述】:

我有一个带有三个选项卡的 UITabViewController。在其中一个选项卡上,用户点击一个按钮,一个新的 UIViewController 控制器会以横向模式弹出(供用户用手指签名)。用户完成后,他们点击 Finish 按钮并调用 finish() 来关闭正在签名的 UIViewController。

我面临的问题是,即使设置了屏幕,用户返回的处于纵向模式的屏幕现在也处于横向模式:

override var supportedInterfaceOrientations: UIInterfaceOrientationMask{
    return .portrait
}

override var shouldAutorotate: Bool {
    return true
}

我无法强制旋转回纵向。我已阅读以下帖子:How to force device rotation in Swift?,据我了解,我无法将屏幕旋转回纵向?

【问题讨论】:

标签: ios swift rotation uiviewcontentmode


【解决方案1】:

这真的很简单。编写以下代码并更改要以编程方式旋转的 ViewControllers 中的方向值。

override func viewWillAppear(_ animated: Bool) {
        let value = UIInterfaceOrientation.portrait.rawValue //Change orientation according to your scenario
        UIDevice.current.setValue(value, forKey: "orientation")
    }

【讨论】:

    猜你喜欢
    • 2011-11-18
    • 2013-02-14
    • 1970-01-01
    • 1970-01-01
    • 2012-03-27
    • 1970-01-01
    • 2010-10-07
    • 2011-04-10
    • 1970-01-01
    相关资源
    最近更新 更多