Iphone iOS 6在设备旋转时崩溃

Iphone iOS 6在设备旋转时崩溃,iphone,ios6,orientation,device-orientation,Iphone,Ios6,Orientation,Device Orientation,这不是一个重复的问题。尚未提供最终的工作解决方案。在我接受答案或找到并提供我自己的解决方案之前,请不要关闭此问题。谢谢 ================================================================== 使用Xcode 4.5.1,我有一个选项卡栏应用程序,其中有5个选项卡。每个选项卡都包含一个UINavigationController。因此,整个应用程序需要在纵向模式下查看,只有一个ViewController例外——一个全屏打开的“模式”V

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

================================================================== 使用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!'

有什么建议吗?

请检查您使用的xcode版本

您使用了XCODE 4.5:
shouldAutorotateToInterfaceOrientation
委托折旧

在项目中使用以下行

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
    }

-(BOOL)shouldAutorotate
{
    return YES;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}

记住一件事。在iOS 6中

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
不推荐使用


您不能在iOS 6中使用它。要在UINavigationController的ViewController中支持不同的界面方向,您需要对UINavigationController进行子类化或对其进行分类。

您需要使用此选项以避免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

代码看起来不错。它不应该仅仅因为这些方法而崩溃。 问题可能在代码的另一部分。 然而,在这里我想告诉你。 上面的
shouldAutorotateToInterfaceOrientation
methods在iOS 6中不推荐使用方向方法。 如果您想了解更多如何解决定向问题

在此处回答:确保将其放在堆栈中最顶部的viewController中。不工作。1) 在
supportedInterfaceOrientations
方法中,您返回
MaskAll
-这是否也应该在P列表中执行?还是P-List只支持纵向?2) 当你说“最上面的viewController”时,是UINavigationController还是tabBarController?如果它是tabBarController,则它的init'd在AppDelegate文件中-因此您将此代码放在AppDelegate中?
***由于未捕获的异常“UIApplicationInvalidInterfaceOrientation”而终止应用程序,原因是:“preferredInterfaceOrientationForPresentation必须返回支持的接口方向!”检查此链接谢谢-我知道
应该自动旋转方向盘方向盘
已被弃用-您能否进一步解释必须将
UINavigationController子类化
?示例代码?我是否必须为项目中的每个
UINavigationController
执行此操作?我有几十个…你所需要做的就是将UINavigationController子类化,并将该子类用作应用程序中的导航控制器。你只需在应用程序中执行一次。看看这个链接:好的,我来试试。但这太疯狂了——必须将UINavigationController子类化。为了让曾经如此简单的东西再次发挥作用,我们不得不跳出障碍。多么可爱的苹果啊。(当然,谢谢你的建议:-)没错,苹果最近让开发者们疯狂了:)