【问题标题】:How to get InterfaceOrientation from iPhone (not DeviceOrientation)?如何从 iPhone 获取 InterfaceOrientation(不是 DeviceOrientation)?
【发布时间】:2011-03-25 18:53:09
【问题描述】:

我创建了一个 modalviewcontroller,所有的子视图都是由代码创建的。当我测试应用程序时,我发现了一个问题。那么问题的主要原因是应用程序不应该支持 UpsideDown 方向,但设备可能恰好处于该方向。

如果我:

  1. 将设备旋转到纵向,然后旋转到 UpsideDown 模式和 presentModalView,modalviewcontroller 中的子视图应该与纵向相同。

  2. 将设备旋转到横向,然后旋转到 UpsideDown 模式和 presentModalView,子视图应该区别对待。

上面的情况告诉我应该按照之前的InterfaceOrientation在modalviewcontroller中创建子视图。

问题是:如何获取上一屏的InterfaceOrientation?在这种情况下,获取设备方向不会有任何帮助。

PS:我正在编写一个库,我可能会为我的用户提供从-willRotateToInterfaceOrientation:duration: 向我发送“toInterfaceOrientation”的界面,但是对于如何在我的代码中获取方向有什么想法吗?

【问题讨论】:

    标签: iphone rotation orientation


    【解决方案1】:

    在任何 UIViewController 中,您都可以像这样访问属性 interfaceOrientation:

    if (self.interfaceOrientation == UIInterfaceOrientationPortrait) {
        // do stuff
    }
    

    【讨论】:

    • 注意: interfaceOrientation 在 iOS 8.0 版中已弃用
    【解决方案2】:
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
       return UIInterfaceOrientationIsPortrait(interfaceOrientation);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-22
      • 2011-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多