UIViewController在iPad上处理iOS 6.0的方向

时间:2012-10-06 14:01:24

标签: ios ipad uiviewcontroller ios6

在我的应用程序中,我需要为ViewControllers处理不同的方向。

  1. ViewController1必须仅支持landascape方向。
  2. ViewController2必须支持横向+纵向方向。
  3. 我在Summury项目中启用了所有这样的方向:

    Summary project orientation

    所以,我在ViewController1

    中插入了这段代码
    - (BOOL)shouldAutorotate
    {
        return YES;
    }
    
    - (NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskLandscape;
    }
    

    我将此代码插入ViewController2

    - (BOOL)shouldAutorotate
    {
        return YES;
    }
    
    - (NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskAll;
    }
    

    问题是ViewController1也是纵向旋转(它应该只支持横向)。

    有什么想法吗?

    非常感谢你们!

2 个答案:

答案 0 :(得分:1)

你的viewController是你的rootViewController吗? 如果没有,那可能是你的问题。

如果你的rootViewController是一个UINavigationController,你应该知道它不会将这些消息转发给它的topViewController。因此,如果是这种情况,我建议您使用UINavigationController的子类,在其中覆盖这些新方法以转发到topViewController。

答案 1 :(得分: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; }

希望有所帮助

祝你好运

相关问题