如何从iPhone获取InterfaceOrientation(而不是DeviceOrientation)?

Chi*_*ong 0 iphone rotation orientation

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

如果我:

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

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

上面的情况告诉我,我应该根据之前的InterfaceOrientation在modalviewcontroller中创建子视图.

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

PS:我正在写一个lib,我可以给我的用户提供接口给我发送" toInterfaceOrientation" -willRotateToInterfaceOrientation:duration:但是有没有关于如何在我的代码中获取方向的想法?

ric*_*son 9

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

if (self.interfaceOrientation == UIInterfaceOrientationPortrait) {
    // do stuff
}
Run Code Online (Sandbox Code Playgroud)