2013-04-30 40 views
0

我开始了一个示例项目,并将以下代码添加到了我的视图控制器中。发布后,屏幕将呈现风景。 然后我去了我的故事板,点击我唯一的视图, - >编辑器 - >嵌入 - >导航控制器。再次启动程序:屏幕将显示为纵向,无论我尝试什么,都不会改变为横向。这是为什么? (所有的方位都在我的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

在iOS 6中,规则是,一旦你在一个UINavigationController的supportedInterfaceOrientations视图控制器(视图控制器)是不相关的。咨询的唯一事项是:

  • 该应用程序(Info.plist)。

  • 应用程序的委托(application:supportedInterfaceOrientationsForWindow:

  • 根视图控制器,而你的情况是现在的UINavigationController

现在,我不完全理解为什么你的UINavigationController是给你一个只有肖像的结果。但我知道,如果你想控制什么UINavigationController做的旋转,你将不得不继承UINavigationController,使这个导航控制器是你的子类的一个实例,并把supportedInterfaceOrientations代码放入你的子类。

注意我试图做你说你做了什么,以及我的机器上,导航控制器确实进行补偿旋转到三个标准的方向。所以我不明白你为什么说它只是肖像。但是,答案依然如此。

+0

你说得对。子类化后,我确实设法旋转到风景,但如果我将添加' - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationPortrait;这个'ViewController'将是纵向的(而其他视图控制器将在横向启动),所以说“这个视图控制器(ViewController)的supportedInterfaceOrientations是不相关的”是一半正确的。我错了吗? – Segev 2013-04-30 18:40:56

+0

'preferredInterfaceOrientationForPresentation'是无关紧要的。这不是“演示”情况。 – matt 2013-04-30 18:42:02

+0

关于你的笔记。我正在讨论视图启动的方向(不旋转设备)。我还没有完全致力于我的工作,但我会为此另外提出一个问题。谢谢。 – Segev 2013-04-30 19:00:17

相关问题