why is my view still presented in landscape?

被刻印的时光 ゝ 提交于 2019-12-04 06:30:34

问题


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:


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")
}


来源:https://stackoverflow.com/questions/32707641/why-is-my-view-still-presented-in-landscape

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!