父UIViewController在关闭后不会更改方向

时间:2018-11-15 13:45:22

标签: ios swift orientation

我有一个UIViewController(称为B),我想以横向显示(强制)它。所有其他UIViewControllers均以纵向模式显示。在我的项目设置中,仅选择了纵向模式。 我的问题是,当我从B回到A时,它停留在风景模式下。

内部AppDelegate:

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
    if #available(iOS 10.0, *) {
        if self.window?.rootViewController?.presentedViewController is CheckImageCameraViewController {
            return UIInterfaceOrientationMask.landscapeRight
        } else {
            return UIInterfaceOrientationMask.portrait
        }
    } else {
        // Fallback on earlier versions
    }
    return UIInterfaceOrientationMask.portrait
}

在控制器A中;

let controllerB = ControllerB()
self.present(controllerB,animated:true,completion:nil)

在控制器B中;

override func viewDidLoad() {
    super.viewDidLoad()


    let value = UIInterfaceOrientation.landscapeRight.rawValue
    UIDevice.current.setValue(value, forKey: "orientation")
}
func closeButtonTapped(){
self.dismiss()
}

编辑:当它在A上时,如果我移动手机以更改方向。它看起来像人像。

1 个答案:

答案 0 :(得分:1)

在A中覆盖viewWillAppear(),检查方向并采取适当的措施。

相关问题