2013-04-30 74 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

相關問題