Tab-Bar应用程序在iOS6中的设备轮换时崩溃

时间:2012-11-01 17:08:27

标签: iphone rotation ios6 uiinterfaceorientation

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

=============================================== ===================
使用Xcode 4.5.1,我们有一个标签栏应用程序,其中包含5个标签。每个选项卡都包含一个UINavigationController,因此需要在纵向模式下查看整个App。有一个例外:我们需要打开并在全屏模式下以“LANDSCAPE”模式查看的“图像库”类型视图控制器。

我们能够在iOS5中使用以下代码在一个特定的ViewController中轻松完成此操作:

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

shouldAutorotateToInterfaceOrientation已在iOS6中弃用,不再有效。
因此,为了让它在iOS6中运行,到目前为止我们采取了以下步骤:
1)创建了UITabBarController的子类(这是我们的rootViewController)
2)将其supportedInterfaceOrientationspreferredInterfaceOrientationForPresentation设置为UIInterfaceOrientationMaskPortrait(但请注意,我们未在其中实施shouldAutorotate方法)
3)将PROJECT / Target支持的方向设置为ALL

这个ALMOST完美运行:我们的“图像库”ViewController确实响应两种横向模式 - 它应该 - 但它最初仍然以纵向打开 - 这很糟糕。我们需要它在景观中开放 - 并且永远不能在肖像中显示。现在它仍然在做两件事。

知道为什么会这样做 - 或者如何解决它?

2 个答案:

答案 0 :(得分:1)

我在使用的应用程序中遇到了同样的问题,这就是我解决它的方法。

首先,我创建了一个名为UITabBarController的{​​{1}}子类,其中包含纵向代码

NonRotatingTabBarController.h

NonRotatingTabBarController

NonRotatingTabBarController.m

#import <UIKit/UIKit.h>

@interface NonRotatingTabBarController : UITabBarController
@end

现在,当您创建Tab Bar Controller时,它需要是NonRotatingTabBarController的实例

#import "NonRotatingTabBarController.h"

@implementation NonRotatingTabBarController

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

@end

现在在需要具有横向支持的ONLY视图控制器中,您需要覆盖旋转方法以使其旋转。在我的情况下,它必须固定为风景

self.tabBarController = [[NonRotatingTabBarController alloc] init]; // or whatever initialising code you have but make sure it's of type NonRotatingTabBarController

在您的项目/目标设置中,您必须为您的应用程序使用的所有界面方向启用支持,否则它将崩溃。让上面的代码处理旋转启用/禁用。

Xcode Project Settings

希望有所帮助!

答案 1 :(得分:1)

在iOS 6中不推荐使用theAutorotateToInterfaceOrientation方法

尝试实现以下方法。

-(BOOL)shouldAutomaticallyForwardAppearanceMethods{   
     // This method is called to determine whether to 
     // automatically forward appearance-related containment
     //  callbacks to child view controllers.
}
-(BOOL)shouldAutomaticallyForwardRotationMethods{
    // This method is called to determine whether to
    // automatically forward rotation-related containment 
    // callbacks to child view controllers.
}

注意:iOS 6中仅支持这些方法。

相关问题