仅在iOS 6上旋转的应用程序,在iOS 5上无法旋转。

4

我制作了一个针对iOS 5和iOS 6的应用程序,但由于某种原因,在使用iOS 5设备(无论是iPhone还是iPad)时,它不会旋转,而只有在使用iOS 6设备时才能旋转。我的应用程序是通用的。请帮助我解决这个问题!谢谢

5个回答

8
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return ((toInterfaceOrientation == UIInterfaceOrientationPortrait) || (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown));
}

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

在您所有的UIViewController子类中覆盖这两个方法......这将适用于iOS 6及更早版本。

1
请注意,此示例仅支持两种状态:'upright'(纵向)和 'upside-down'(倒立)。 - Gonen

5

iOS 5和iOS 6调用不同的方向和旋转代理。在iOS 5中,实现:

shouldAutorotateToInterfaceOrientation:,在iOS 6中已被弃用。

因此,在iOS 6中,请确保设置根视图控制器,并实现:

shouldAutorotate:, supportedInterfaceOrientations和supportedInterfaceOrientationsForWindow:


0

我遇到了类似的问题。您可以检查这个问题的答案:

iOS6上旋转行为不同

总结一下,在iOS 5和iOS 6中使自动旋转完全工作,并且处理PortraitUpsideDown方向,我不得不实现一个自定义的UINavigationController,并将其分配给self.window.rootViewController在应用程序代理的didFinishLaunchingWithOptions方法中。


0

shouldAutorotateToInterfaceOrientation在iOS6中已被弃用。

所以如果你想在两个操作系统版本上运行应用程序,那么也要添加shouldAutorotateToInterfaceOrientation,如下所示

//for ios6
 - (BOOL)shouldAutorotate {

        UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];

        if (orientation == UIInterfaceOrientationLandscapeLeft  ||orientation ==  UIInterfaceOrientationLandscapeRight ) 
{

            return YES;
        }
        return NO;
        }

//for ios5

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    //interfaceOrientation == UIInterfaceOrientationLandscapeRight; 
    if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft  ||interfaceOrientation ==  UIInterfaceOrientationLandscapeRight ) {

        return YES;
    }
    return NO;
}

-1
为了支持iOS5和iOS6中的自动旋转,我们需要在iOS6中提供回调...`[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];`
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];

我们需要调用

- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;

}

-(BOOL)shouldAutoRotate{
    return YES;
  }

适用于ios5

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation

{ return ((toInterfaceOrientation == UIInterfaceOrientationPortrait) || (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)); }

返回值为真,如果设备方向是竖屏或者倒置的竖屏。


嗯...我不是已经格式化过这个了吗?不,那是另一个副本:所以请不要在多个问题上发布完全相同的答案:要么对所有问题都不适用,要么这些问题是重复的,应该标记/关闭为重复。 - kleopatra

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接