为什么iPhone 5不会旋转到upsideDown

Jea*_*ler 25 xcode rotation ios6

我在我的代码中添加了新的方法,如苹果iOS 6 Documentations中所述,但在iPhone 5上,应用程序不会颠倒过来.只有景观方式.

这里我的代码来自rootViewController:

- (NSUInteger)supportedInterfaceOrientations{
    NSLog(@">>> Entering %s <<<", __PRETTY_FUNCTION__);
    return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft |
            UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown);
}
- (BOOL)shouldAutorotate{
    NSLog(@">>> Entering %s <<<", __PRETTY_FUNCTION__);
    return YES;
}
Run Code Online (Sandbox Code Playgroud)

我也尝试了"UIInterfaceOrientationMaskAll"但没有变化.奇怪的是,我的带有iOS6的iPhone 4使用相同的代码完全颠倒了o.

有任何想法吗?

Cli*_*udo 61

IOS 6使用UIInterfaceOrientationMaskAlliPad和UIInterfaceOrientationMaskAllButUpsideDowniPhone的默认方向.如果您希望iPhone上的ViewControllers旋转到包括UpsideDown在内的所有方向,您必须添加iOS 6方法:

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}
Run Code Online (Sandbox Code Playgroud)

所有视图控制器.如果你已经完成了这个并且它没有工作那么我打赌你使用TabViewController或NavigationController,其中一些视图没有返回这个.所有ViewControllers都必须为其中的任何一个返回它以支持它.

或者,您可以将类别添加到作为rootViewController的UITabViewController或NavigationController类,并覆盖该方法.你是这样做的:

@interface UITabBarController (RotationAll)
    -(NSUInteger)supportedInterfaceOrientations;
@end

@implementation UITabBarController (RotationAll)
-(NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}
@end
Run Code Online (Sandbox Code Playgroud)

这些是苹果开发人员论坛中目前正在讨论的目前推荐的方法,苹果工作人员说早期的文档不鼓励对UINavigationController进行子类化已经过时,而且从iOS 6开始就可以做到这一点.

  • 很好的答案. (2认同)

小智 12

感谢Cliff Ribaudo真的帮助您完成基于UITabbarController的项目的答案,但在我的情况下,我只使用UINavigationController,所以我已经修改了UINavigationController categeory的答案.

@interface UINavigationController (RotationAll)
-(NSUInteger)supportedInterfaceOrientations;
@end   


@implementation UINavigationController (RotationAll)
  -(NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
  }
@end
Run Code Online (Sandbox Code Playgroud)