Xcode 4.5.2 GM种子版本中的方向问题,带有iOS 6



我在iPhone应用程序上都有两个肖像方向支持(肖像和肖像upsidedown)。

在早期的xcode4.5.1中,我通过以下方式解决了此问题:

  • 在AppDelegate中设置rootviewController
  • 提及应该这样的autorotatetointerfaceorientation:

    -(BOOL)shouldAutorotateToInterfaceOrientation:    (UIInterfaceOrientation)toInterfaceOrientation {
         return UIInterfaceOrientationIsPortrait(toInterfaceOrientation);   }  
    
  • 在info.plist文件中提及支持的Interfaceorientation

现在,我正在为较新的Xcode做同样的事情,但是在iPhone Simulator v6.0中,它不正确支持旋转。

我也尝试了这些方法:

-(BOOL) shouldAutorotate {
  BOOL returnValue = NO;
  int interface =  [self preferredInterfaceOrientationForPresentation];
  if(UIInterfaceOrientationIsPortrait(interface)) {
    // Code to handle portrait orientation
    returnValue = YES;
  }
  else {
    // Code to handle Landscape orientation
    returnValue = NO;
  }
  return returnValue;
}
- (NSUInteger) supportedInterfaceOrientations {
  return (UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown);
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
  return (UIInterfaceOrientationPortrait |
          UIInterfaceOrientationPortraitUpsideDown);
}

请指导我如何支持iOS> 4.3所有版本的肖像方向。

预先感谢Mrunal

为什么方向更改为iOS 6?

从iOS 6.0开始,有几种方向更改使我的应用程序无法从肖像中旋转。我的修复程序,以及在这里适用的修复程序,是您必须在AppDelegate的窗口上进行setRootViewController。较早的答案提供了几个正确的建议,但错过了与我相关的一项。

application didFinishLaunchingWithOptions中,之后:

[window makeKeyAndvisible]

[window addSubview: viewController.view];

您必须替换为:

if([[UIDevice currentDevice].systemVersion floatValue] >= 6.0) {
    [window setRootViewController:viewController];
} else {
    [window addSubview: viewController.view];
    (or [window makeKeyAndvisible])
}

您还需要添加新的shouldAutoRotate,而不是折旧的shouldAutorotateToInterfaceOrientation,但这更容易找到,对我来说更少。

与确保所有方向都在.plist文件中指定。

我不需要覆盖supportedInterfaceOrientations,因为我对默认方向感到满意(全部适用于iPad UIInterfaceOrientationMaskAll,除了iPhone UIInterfaceOrientationMaskAllButUpsideDown的倒置外,所有这些)。

我必须承认,当iOS 6来临时,我摆弄了这个,直到我有东西可以工作,然后停下来。但是,这是我的猜测:

我相信,当您可能想要动态更改您的应用程序是否完全支持自动旋转时,shouldAutorotate旨在在情况下使用。我认为您不打算告诉您支持哪个方向(例如原始shouldAutorotateToInterfaceOrientation:方法)。因此,如果您的应用程序支持任何自动启动,我认为您应该这样做:

-(BOOL) shouldAutorotate {
   return YES;
}

supportedInterfaceOrientations是您应该识别方向的地方。

但是,在这种方法中,您的执行方式与我一直使用的操作不同(可能或可能不是问题)。我认为您应该将 bask 常数用于此方法。因此,而不是这个:

- (NSUInteger) supportedInterfaceOrientations {
   return (UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown);
}

使用此:

- (NSUInteger) supportedInterfaceOrientations {
   return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
}

另外,我认为preferredInterfaceOrientationForPresentation方法不应该返回多个方向。首选可能只是一个,例如:

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
  return UIInterfaceOrientationPortrait;
}

这是相关的Apple文档

更新:

您可能尝试使用的另一件事是使用此方法:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
}

在您的应用程序委托类中。此方法是可选的,但是可以设置应用程序支持的方向的默认值,以防您在所有视图控制器中或在应用程序的plist文件中指定它们。由于您没有显示您的plist文件和其他视图控制器,因此我无法确定这是否可能有帮助。但是,这可能是可以尝试的。

最新更新