2

我在 UITabBarController 中有一个 UINavigationController。我尝试了社区关于 iOS 6 中自动旋转的所有建议,但没有成功,最后我决定为 UINavigationController 创建一个类别,该类别没有对 orientaion 进行任何更改(尽管确实调用了这些函数)

在此处输入图像描述

然后我为 UITabBarController 创建了一个类别,如下所示:

#import "UITabBarController+ios6Rotate.h"

@implementation UITabBarController (ios6Rotate)

-(BOOL)shouldAutorotate
{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortraitUpsideDown;;
}

@end

得到了这个:

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

但是我所有的方向都支持?!唔

然后我将代码更改为:

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortraitUpsideDown;
}

这使我的应用程序颠倒了,但仍然不会旋转。我不明白发生了什么事。在这一点上,我想在 ios6 中看到任何形式的旋转,我不在乎哪一边,但似乎没有任何效果。

4

2 回答 2

2

您应该确保添加正确的supportedInterfaceOrientations. 您可以尝试在您的类别中调用相应viewController的方向方法。

例如在UINavigationController类别中它会是这样的

-(BOOL)shouldAutorotate
{  
  return   [self.topViewController shouldAutorotate];   
}

-(NSUInteger)supportedInterfaceOrientations
{
   return [self.topViewController supportedInterfaceOrientations];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
   return [self.topViewController preferredInterfaceOrientationForPresentation];
}
于 2013-04-08T09:49:35.493 回答
2

我花了几个小时才弄清楚。这是解决方案:由于某种原因,previos 程序员做了这样的事情:

 [window addSubview:[someController view]];  // In the appDelegate

我需要做的就是用这个替换它:

  [self.window setRootViewController:someController];

自动旋转方向重新开启!

于 2013-04-08T11:05:05.627 回答