为什么我的视图仍然以横向呈现?

why is my view still presented in landscape?

我的视图由导航控制器控制,所以我将导航控制器中支持的方向设置为显式纵向和纵向向上侧向下,这有效,但是如果调用视图时前一个视图处于横向,它将以横向显示并保持横向直到设备旋转。我该如何防止这种情况?

这是我的代码:

class EditProfileViewController: UIViewController, UINavigationControllerDelegate

override func viewDidLoad() {
        super.viewDidLoad()

        navigationController?.delegate = self
}

func navigationControllerSupportedInterfaceOrientations(navigationController: UINavigationController) -> UIInterfaceOrientationMask {

    return [UIInterfaceOrientationMask.Portrait, UIInterfaceOrientationMask.PortraitUpsideDown]
}

我认为上一行会将视图永久锁定为纵向,我该怎么做?

您可以在关闭之前将方向改回纵向:

UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue, forKey: "orientation")

dismiss(animated: true) { _ in
    print("dismissed in Portrait mode")
}