【问题标题】:iOS 6 orientation changes have me totally confusediOS 6 的方向变化让我完全困惑
【发布时间】:2012-12-15 18:12:20
【问题描述】:

这是一个通用应用程序,我将 iPhone 和 iPad 目标支持的界面方向设置为横向左右。我的根视图控制器不使用 NavigationController 并且 xib 是面向横向的视图。该应用旨在仅使用横向。

在应用程序中:didFinishLaunchingWithOptions 我有...

if (([JLHelper isIPhone]) | ([JLHelper iPadPortraitRestricted])) {
         application.statusBarOrientation = UIInterfaceOrientationLandscapeRight;
}

在 iOS 5 中一切正常,但在 iOS 6 中,视图在启动时不会以横向显示。

我了解 shouldAutorotateToInterfaceOrientation 在 iOS 6 中已被弃用,但我不明白为什么这会影响初始演示。在我看来,根视图正在旋转。

我已经阅读了很多关于如何在 iOS 6 中强制横向的讨论,现在我完全糊涂了。必须有一种简单的方法来实现只使用横向的应用程序。

【问题讨论】:

    标签: iphone ios6 orientation


    【解决方案1】:

    您可以在 iOS 6 的 info.plist 中指定支持的方向。此外,您可以实现 shouldAutorotate 方法和 supportedInterfaceOrientations 方法(iOS 6 的新功能)来有条件地限制 iOS 6 的方向。

    请注意,如果您想继续支持 iOS 5,您还必须使用 shouldAutorotateToInterfaceOrientation... 方法。 iOS 5 使用旧方法,iOS 6 使用新方法,它们可以共存。

    【讨论】:

    • 感谢您的回复。横向在 info.plist 中实现,在我的例子中是 jetLogger-info.plist。我还在我的根 viewController 中包含了方法 shouldAutorotate,返回 NO 和 supportedInteraceOrientations,返回 UIInterfaceOrientationMaskLandscape。视图仍然没有横向显示。
    • 好的,我搞定了。 shouldAutorotaate 必须返回 YES。新的变化现在对我来说很有意义。 shouldAutorotate 简单地声明应用程序是否应该允许自动旋转而不管方向。 supportedInterfaceOrientations 控制哪些方向将自动旋转。我发现如果您在 info.plist 中实现了方向,则不需要调用supportedInterfaceOrientations
    • 一个重要说明。为了使整个工作正常,您必须使用 window.rootViewController = viewController;而不是 [window addSubview:viewController.view];在您的应用程序中:didFinishLaunchingWithOptions:launchOptions 方法。
    • 是的,window 上的 rootViewController 自 iOS 3 以来就一直存在,但像许多开发人员一样,我们刚刚离开了 Xcode 模板中的旧代码,这些代码一直持续到 iOS 5.1。 iOS 6 是第一个需要 rootViewController 集的系统。
    猜你喜欢
    • 2015-06-17
    • 1970-01-01
    • 1970-01-01
    • 2014-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-18
    • 1970-01-01
    相关资源
    最近更新 更多