0

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

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

override var supportedInterfaceOrientations: UIInterfaceOrientationMask{
    return .portrait
}

override var shouldAutorotate: Bool {
    return true
}

我无法强制旋转回纵向。我读过以下帖子:如何在 Swift 中强制设备旋转?据我了解,我无法将屏幕旋转回纵向?

4

1 回答 1

0

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

override func viewWillAppear(_ animated: Bool) {
        let value = UIInterfaceOrientation.portrait.rawValue //Change orientation according to your scenario
        UIDevice.current.setValue(value, forKey: "orientation")
    }
于 2018-12-03T10:44:57.527 回答