Autorotate适用于iOS 6,但在iOS 5中提供了奇怪的行为

时间:2012-11-01 14:47:35

标签: ios ios5 ios6 autorotate

我似乎从这篇文章中遇到了相反的问题:

Autorotate in iOS 6 has strange behaviour

当我将付费应用程序提交给Apple时,XCode让我在测试设备上更新了iOS 6。我在XCode中使用GUI将我的应用程序设置为仅在iPhone上以纵向模式显示,并且仅在iPad上以横向模式显示。这在我的iOS 6 iPhone和iPad上运行良好。然而,在iOS 5中,iPad允许应用程序旋转为纵向,在不应该存在的信箱类黑色区域中显示我的按钮,并且反复崩溃。

我正在使用导航控制器和故事板。

我知道在iOS 6中不推荐使用AutorotateToInterfaceOrientation,但是在iOS 5中仍然应该调用它,我试过这个:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        if ((UIDeviceOrientationIsLandscape(UIDeviceOrientationLandscapeLeft))||(UIDeviceOrientationIsLandscape(UIDeviceOrientationLandscapeRight))) {
            return YES;
        }
        else return NO;
    }
    else
    {
        if ((UIDeviceOrientationIsLandscape(UIDeviceOrientationPortrait))||(UIDeviceOrientationIsLandscape(UIDeviceOrientationPortraitUpsideDown))) {
            return YES;
        }
        else return NO; }
    // Return YES for supported orientations
}

上面的代码似乎没有做任何事情。我把它放在我的每个视图控制器中;看起来我应该把它放在我的导航控制器中,但因为我用图形方式设置它,我不知道该怎么做。我是否必须将我的导航控制器子类化并在代码中执行所有操作?必须有一种方法来使用故事板设置!

(注意:我没有使用AutoLayout,显然不能因为一些较旧的组件,我包括我的软件,但显然不喜欢它。)

可能导致这种情况的原因是什么?在太多人购买应用程序并抱怨之前,我想解决它!提前谢谢......

1 个答案:

答案 0 :(得分:2)

我认为代码应该是这样的,你使用“ interfaceOrientation ”,参数传递给方法进行比较:

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
    if ((UIDeviceOrientationIsLandscape(interfaceOrientation))||(UIDeviceOrientationIsLandscape(interfaceOrientation))) {
        return YES;
    }
    else return NO;
}
else
{
    if ((UIDeviceOrientationIsLandscape(interfaceOrientation))||(UIDeviceOrientationIsLandscape(interfaceOrientation))) {
        return YES;
    }
    else return NO; }