我的视图由导航控制器控制,因此我将支持的方向设置到导航控制器中以显式纵向 &PortraitUpSideDown 并且这有效,但是如果在调用视图时之前的视图处于横向状态,它将以横向形式呈现并保持横向状态,直到设备旋转.我该如何防止这种情况发生?
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?
这是我的代码:
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?
您可以在关闭它之前将方向更改回纵向:
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")
}
这篇关于为什么我的视图仍然以横向显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!