【发布时间】:2015-02-21 08:34:53
【问题描述】:
在我介绍 UINavigationController 之前,我的应用程序正在横向旋转。现在看起来 UINavigationController 旋转了,但 viewcontroller 没有。我一遍又一遍地阅读了所有文档,但我无法弄清楚。
这是我在 appDelegate 中的代码
// UINAVIGATIONCONTROLLER
let ksNavigationController = KSNavigationController()
// UIVIEWCONTROLLER
let gameViewController = GameViewController()
ksNavigationController.pushViewController(gameViewController, animated: false)
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
self.window?.rootViewController = ksNavigationController
我阅读了苹果的文档:
从 iOS 6 开始,只有最顶层的视图控制器(与 UIApplication 对象一起)参与决定是否旋转以响应设备方向的变化。通常,显示内容的视图控制器是 UINavigationController、UITabBarController 或自定义容器视图控制器的子级。您可能会发现自己需要子类化一个容器视图控制器,以便修改其supportedInterfaceOrientations 和shouldAutorotate 方法返回的值
所以我已经在我的 UINavigationController 子类中做到了
override func shouldAutorotate() -> Bool {
return true
}
override func supportedInterfaceOrientations() -> Int {
return Int(UIInterfaceOrientationMask.Landscape.rawValue)
}
它不起作用。我的 UIViewController 不会旋转。我可以以代码的形式获得一些帮助吗?谢谢。
【问题讨论】:
标签: ios objective-c xcode swift uikit