2012-10-06 26 views
3

在我的應用程序,我需要處理不同的方向我ViewControllers的UIViewController手柄方向的iOS 6.0的iPad

  1. ViewController1只能支持landascape方向。
  2. ViewController2必須支持橫向+縱向。

啓用,在Summury項目中,所有的方向是這樣的:

Summary project orientation

所以,我在ViewController1插入此代碼:

- (BOOL)shouldAutorotate 
{ 
   return YES; 
} 

- (NSUInteger)supportedInterfaceOrientations 
{ 
   return UIInterfaceOrientationMaskLandscape; 
} 

我插入ViewController2這個代碼:

- (BOOL)shouldAutorotate 
{ 
   return YES; 
} 

- (NSUInteger)supportedInterfaceOrientations 
{ 
   return UIInterfaceOrientationMaskAll; 
} 

問題是ViewController1也以縱向方向旋轉(它應該只支持橫向)。

有什麼想法?

非常感謝大家!

+0

[此鏈接可以幫助你(http://stackoverflow.com/a/12651309/1059705) – Bala

+0

我已經看過這個討論,但它不是有益的,我 – MaTTP

+0

這是一個有點棘手。這可能會幫助你:http://stackoverflow.com/q/12755727/653513 –

回答

1

是您的viewController你RootViewController的? 如果不是,那可能是你的問題。

如果你的RootViewController的是一個UINavigationController,你應該知道它的topViewController它不轉發這些消息。所以,如果這是你的情況,我建議你使用UINavigationController的子類,在其中你重寫這些新的方法,以轉發到topViewController。

0

的iOS 6之前,這工作得很好

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientatio n { if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) return YES; 

else return NO; } 

但在iOS 6中已被棄用

現在你應該指定想要的方向,並選擇一個方向呈現

你應該寫

- (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscape; } 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationLandscapeRight; } 

希望它可以幫助

好運