UIViewController 如何处理 iPad 上 iOS 6.0 的方向问题

3

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

  1. ViewController1 必须只支持横向方向。
  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也会在竖屏方向旋转(它应该只支持横屏方向)。

有什么想法吗?

非常感谢大家!


这个链接可能会对你有所帮助:https://dev59.com/jWcs5IYBdhLWcg3wrmDC#12651309 - Bala
我已经阅读了这个讨论,但对我没有帮助。 - MaTTP
有点棘手。这可能会对您有所帮助:https://dev59.com/i2nWa4cB1Zd3GeqPykTY - Rok Jarc
你解决了这个问题吗?我在iOS6上也遇到了类似的旋转问题。 - Stas
2个回答

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; }

希望能有所帮助
祝你好运

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接