0

我有一個推UIViewController(孩子)的UINavigationController(父)。我知道這兩個都需要支持:如何爲子視圖執行橫向方向,但不是父視圖?

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    // Return YES for supported orientations 
    return YES; //(interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

但是,我不希望家長能夠旋轉橫向。我如何執行此操作?

UPDATE:

我的父母已經更新到:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
      if (interfaceOrientation != UIInterfaceOrientationLandscapeRight ||interfaceOrientation != UIInterfaceOrientationLandscapeLeft) 
      return NO; 
      else 
      return YES; 
} 

但現在的孩子不旋轉。

回答

1

在你的父級視圖控制器中,你將需要實現這個。如果你還沒有子類化父母使用的UINAvigationController,只需要添加這個方法即可。

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    if (interfaceOrientation != UIInterfaceOrientationLandscape) 
     return NO; 
    else 
     return YES; 
} 

在子視圖控制器子類,實現方法是你一個人:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    // Return YES for supported orientations 
    return YES; //(interfaceOrientation == UIInterfaceOrientationPortrait); 
} 
+0

我已修改了小幅的代碼,因爲UIIntefaceOrientationLandscape不編譯瓦特/ iOS4的。但是,孩子停止旋轉。 – 2010-07-02 20:45:34

相關問題