why is my view still presented in landscape?

2019-03-06 14:29发布

my view is controlled by a navigation controller, so I set the supported orientations in to the navigation controller to explicitly portrait & portraitUpSideDown and this works, however if the previous view was in landscape when the view was called upon, it will present itself in landscape and stay in landscape until the device is rotated.. How do I prevent this?

Here is my code:

class EditProfileViewController: UIViewController, UINavigationControllerDelegate

override func viewDidLoad() {
        super.viewDidLoad()

        navigationController?.delegate = self
}

func navigationControllerSupportedInterfaceOrientations(navigationController: UINavigationController) -> UIInterfaceOrientationMask {

    return [UIInterfaceOrientationMask.Portrait, UIInterfaceOrientationMask.PortraitUpsideDown]
}

I thought the previous line would lock the view into portrait permanently, how do I do so?

1条回答
虎瘦雄心在
2楼-- · 2019-03-06 15:25

You can change your orientation back to portrait before dismissing it:

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

dismiss(animated: true) { _ in
    print("dismissed in Portrait mode")
}
查看更多
登录 后发表回答