【问题标题】:iOS 6 Crashes on Device Rotation [duplicate]iOS 6 在设备旋转时崩溃 [重复]
【发布时间】:2012-11-01 03:44:46
【问题描述】:

这不是一个重复的问题。尚未提供最终的工作解决方案。在我接受答案或找到并为此提供我自己的解决方案之前,请不要关闭此问题。谢谢!

================================================ ==================== 使用 Xcode 4.5.1,我有一个标签栏应用程序,其中有 5 个标签。每个选项卡都包含一个 UINavigationController。因此,整个应用程序需要在纵向模式下查看,唯一的 ViewController 除外 - 一个以全屏模式打开并打算在横向模式下查看的“模态” VC。

这在 iOS5 中运行得非常好——我只是在那个特定的 ViewController 中使用了以下代码:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
   return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

但是现在应用崩溃了,并给出了这个错误:

Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation',    
reason: 'preferredInterfaceOrientationForPresentation must return a supported interface orientation!'

有什么建议吗?

【问题讨论】:

标签: iphone ios6 orientation device-orientation


【解决方案1】:

请检查您使用的 xcode 版本。

您使用了 XCODE 4.5:shouldAutorotateToInterfaceOrientation delegate Depreciated。

您在项目中使用以下行。

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
    }

-(BOOL)shouldAutorotate
{
    return YES;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}

【讨论】:

  • 确保将它放在堆栈中最顶层的 viewController 中。
  • 不工作。 1) 在supportedInterfaceOrientations 方法中您返回MaskAll - 这也应该在P-List 中完成吗?还是应该 P-List 只支持肖像? 2) 当你说“最顶层的 viewController”时——是 UINavigationController 还是 tabBarController?如果它是 tabBarController,它会在 AppDelegate 文件中初始化 - 所以你把这段代码放在那里,在 AppDelegate 中?
  • *** Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'preferredInterfaceOrientationForPresentation must return a supported interface orientation!'
【解决方案2】:

您需要使用它来避免 iOS6 崩溃..

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_6_0
- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
{
    return UIInterfaceOrientationMaskAllButUpsideDown; //Getting error here? then update ur xcode to 4.5+
}
#endif

【讨论】:

    【解决方案3】:

    记住一件事。在 iOS 6 中

    -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    

    已弃用。

    您不能在 iOS 6 中使用它。为了在 UINavigationController 的 viewControllers 中支持不同的界面方向,您需要子类化 UINavigationController 或为其创建一个类别。

    【讨论】:

    • 谢谢 - 我知道 shouldAutorotateToInterfaceOrientation 已被弃用 - 你能进一步解释必须继承 UINavigationController 吗?示例代码?我是否必须为我的项目中的每个UINavigationController 执行此操作?我有几十个...
    • 您需要做的就是继承 UINavigationController 并将该子类用作应用程序中的导航控制器。您只需在您的应用程序中执行此操作一次。看看这个链接:wmdeveloper.com/2012/09/ios-6-and-interface-orientation.html
    • 好的 - 我会试一试。不过这很疯狂——必须继承 UINavigationController。不得不跳过铁环来重新制作曾经如此简单的东西。非常Apple。 (但当然感谢您的建议:-))
    • 是的,Apple 这些天让开发者发疯了 :)
    【解决方案4】:

    代码看起来不错。它不应该仅仅因为这些方法而崩溃。 问题可能在代码的另一部分。 但是,在这里我想告诉你。 以上shouldAutorotateToInterfaceOrientation 方法的方向方法已在 iOS 6 中弃用。 如果您想了解更多如何解决方向问题 you should take a look of this

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多