【发布时间】:2015-10-27 16:58:32
【问题描述】:
我有一个应用程序,它由一个包含 4 个导航控制器的标签栏控制器组成。我找不到任何解决方案让导航控制器层次结构中的一个控制器仅处于横向模式。所有其他控制器都应该是纵向的。感谢您对此问题的任何帮助。
【问题讨论】:
标签: ios uinavigationcontroller orientation landscape
我有一个应用程序,它由一个包含 4 个导航控制器的标签栏控制器组成。我找不到任何解决方案让导航控制器层次结构中的一个控制器仅处于横向模式。所有其他控制器都应该是纵向的。感谢您对此问题的任何帮助。
【问题讨论】:
标签: ios uinavigationcontroller orientation landscape
在你想成为横向的导航控制器的viewDidLoad():中,包括:
let value = UIInterfaceOrientation.LandscapeLeft.rawValue
UIDevice.currentDevice().setValue(value, forKey: "orientation")
请务必添加以下覆盖
override func shouldAutorotate() -> Bool {
return true
}
【讨论】:
所以我尝试了以下解决方案,它对我有用:
在 AppDelegate.swift 中:
var currViewController: UIViewController?
func application(application: UIApplication, supportedInterfaceOrientationForWindows window: UIWindow?) -> UIInterfaceOrientationMask {
if currViewController is MyCustomController {
return UIInterfaceOrientationMask.LandscapeLeft
} else {
return UIInterfaceOrientationMask.Portrait
}
}
在 MyCustomController.swift 中:
let oAppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
override func viewDidLoad(){
super.viewDidLoad()
oAppDelegate.currViewController = self
}
【讨论】: