视图控制器不会自动旋转到纵向

时间:2013-09-01 21:01:43

标签: iphone ios objective-c autorotate

我已经实现了一个仅用于自动旋转的视图控制器。所以我称之为RotatableViewController的视图控制器实现了这些方法:

- (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}

- (NSUInteger) supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}

- (BOOL) shouldAutorotate {
    return YES;
}

它应该自动旋转到所有方向,我还检查了目标中支持的界面方向:

enter image description here

但令人难以置信的是,它并没有在镜头中颠倒过来自动旋转:

enter image description here

可能是什么问题?

PS 在iOS 6.1中,视图控制器通过故事板进行实例化。

2 个答案:

答案 0 :(得分:2)

问题在于您使用的是UINavigationController,默认情况下不支持iPhone上下侧。作为一般设计原则,iPhone应用程序不应该支持颠倒(据称因为“锁定”开关确实锁定iPhone上的横向模式,与iPad不同)。倒置方向仅适用于iPad设备。

您可以通过继承UINavigationController并使用返回supportedInterfaceOrientations的{​​{1}}来解决您的问题,并将其指定为故事板中导航控制器的基类。但我不应该这样做,因为iPhone上的应用程序通常不应支持颠倒的纵向方向。

答案 1 :(得分:1)

旧版本存在UIInterfaceOrientationMaskAll问题。不确定您使用的是哪个版本。尝试重做所有方向。

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