为什么我的视图仍然以横向显示? [英] why is my view still presented in landscape?

查看:22
本文介绍了为什么我的视图仍然以横向显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的视图由导航控制器控制,因此我将支持的方向设置到导航控制器中以显式纵向 &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")
}

这篇关于为什么我的视图仍然以横向显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆