仅允许一个UIViewController的多个方向

时间:2015-05-13 08:37:36

标签: ios swift uiviewcontroller uiinterfaceorientation

我希望我的应用的总体方向是纵向,但对于一个特定的$status = $myClass -> mymethod({ server : "localhost", user : "user", password : '123' }) (VC2B),我希望用户能够倾斜设备以横向显示。 (VC2B有一个导航栏)

我尝试了不同类型的代码,但没有运气。理想情况下,我想仅在UIViewController(VC2B)中启用轮换。但这似乎是不可能的,相反,你似乎必须在General部分启用所有方向,然后以编程方式关闭它们 - 这是真的吗?

无论如何,我尝试了各种各样的东西

UIViewController

以下答案建议将override func shouldAutorotate() -> Bool { return true } override func supportedInterfaceOrientations() -> Int { return Int(UIInterfaceOrientation.LandscapeLeft.rawValue) | Int(UIInterfaceOrientation.LandscapeRight.rawValue) | Int(UIInterfaceOrientation.Portrait.rawValue) } 覆盖为false,但如果页面以横向模式加载,那么这不起作用,那么它只会停留在横向上。

Allow all orientations for only one view controller

问题:如果不向所有我的shouldAutorotate添加代码,我怎么能够整洁,只允许一个{{1}的多个方向}?

1 个答案:

答案 0 :(得分:0)

当我遇到同样的情况时,请执行以下操作:

在“常规信息”屏幕中启用所需的方向 在每个ViewController.swift中,覆盖自动旋转功能,使用 true false (对于应该旋转的是true,对于其他旋转为false)