【问题标题】:Can't get embedded UIViewController to rotate无法让嵌入式 UIViewController 旋转
【发布时间】: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


    【解决方案1】:

    您不必编写代码,请确保在应用程序目标->常规选项卡->部署信息中,您检查了横向左和横向右选项以及纵向选项与设备方向字段。

    【讨论】:

    • 横向左右横向勾选。我不想支持纵向方向
    • 然后取消选中 Portrait 和 UpsideDown 选项,只选中 Landscape Right 和 Landscape Left 选项,它对我来说很好用。
    • 这就是我所拥有的......只有左右横向。必须有其他东西阻止视图控制器旋转
    • 你一定在使用故事板,不是吗?
    • 啊,我不得不在情节提要的 GameViewController 中取消选中“是初始视图控制器”。感谢您的帮助!
    猜你喜欢
    • 2010-10-07
    • 1970-01-01
    • 1970-01-01
    • 2011-11-18
    • 2013-05-11
    • 1970-01-01
    • 1970-01-01
    • 2012-03-27
    • 2011-04-10
    相关资源
    最近更新 更多