嵌入导航控制器后,视图不会旋转

时间:2013-04-30 18:22:38

标签: ios objective-c cocoa-touch

我启动了一个示例项目,并将以下代码添加到我的视图控制器中。启动后,屏幕将显示在横向上。 然后我去了我的故事板,点击我唯一的视图, - >编辑 - >嵌入 - >导航控制器。再次启动程序:屏幕将处于纵向状态,无论我尝试什么,都不会改变为横向。这是为什么? (所有方向都在我的plist中启用。)

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

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

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationLandscapeRight;
}

@end

1 个答案:

答案 0 :(得分:1)

在iOS 6中,规则是,一旦你进入UINavigationController,这个视图控制器(ViewController)的supportedInterfaceOrientations就无关紧要了。唯一被咨询的事情是:

  • 应用程序(Info.plist)。

  • 应用代表(application:supportedInterfaceOrientationsForWindow:

  • 根视图控制器,在您的情况下现在是UINavigationController

现在,我并不完全理解为什么你的UINavigationController会给你一个只限肖像的结果。但我知道如果你想控制 UINavigationController对旋转做了什么,你必须继承UINavigationController,使这个导航控制器成为你的子类的一个实例,然后放入supportedInterfaceOrientations代码进入你的子类。

注意我尝试按照您的说法进行操作,在我的机器上,导航控制器 对所有三个标准方向执行补偿旋转。所以我不明白为什么你说它只是肖像。但是,答案仍然是一样的。

相关问题