2012-10-06 27 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; } 

希望它可以帮助

好运