简体   繁体   English

显示模式视图控制器时设备旋转

[英]Device rotation while displaying modal view controller

I have an OpenGL app which supports dynamic device orientation. 我有一个支持动态设备方向的OpenGL应用程序。 I can rotate the device to any of the 4 physical orientations and everything works as expected. 我可以将设备旋转到4个物理方向中的任何一个,一切都会按预期进行。

Now I've added a modal view controller so that you can get a settings view (this is non-OpenGL). 现在,我添加了一个模式视图控制器,以便您可以获取设置视图(这是非OpenGL)。 The modal view controller also supports any device orientation. 模态视图控制器还支持任何设备方向。

However, if I present the modal view controller in orientation A (eg portrait) and dismiss it in orientation B (eg landscape-right), after it is dimissed, the OpenGL view is corrupted (the aspect ratio looks wrong). 但是,如果我在方向A(例如纵向)中显示模态视图控制器,并在方向B(例如,横向右视图)中将其关闭,则在将其消除后,OpenGL视图将损坏(长宽比看起来不正确)。 I have to orient the device to a different orientation for the OpenGL view to 'correct' itself. 我必须将设备定向到其他方向,以使OpenGL视图能够“自行”纠正。

When the modal view controller is dismissed, it's like the app thinks that it's already in orientation B, so it doesn't ever rotate the OpenGL view. 当关闭模式视图控制器时,就像应用程序认为它已经处于方向B一样,因此它永远不会旋转OpenGL视图。

If I disable rotation on the modal view controller, then if I present the modal controller in orientation A, rotate the device to orientation B (the modal view controller no longer rotates) and dismiss the controller, the OpenGL view gets willRotateToInterfaceOrientation/didRotateFromInterfaceOrientation and correctly orients to orientation B. 如果禁用模式视图控制器上的旋转,则如果将模式控制器显示为方向A,将设备旋转到方向B(模式视图控制器不再旋转)并关闭该控制器,则OpenGL视图将获取willRotateToInterfaceOrientation / didRotateFromInterfaceOrientation并正确朝向B。

Is there any way to preserve the dynamic orientation of the modal controller, yet have the OpenGL view also properly rotate after the modal controller is dismissed? 有什么方法可以保持模态控制器的动态方向,但是在取消模态控制器后,OpenGL视图是否也可以正确旋转?

Thank you. 谢谢。

I had a similar issue with a custom action sheet, and decided that the simplest answer would be to temporarily disallow rotation while the view is presented. 我在自定义操作表上遇到了类似的问题,并决定最简单的答案是在显示视图时暂时禁止旋转。 You can see an example of this in the Apple Notes app, whenever an action sheet is presented the orientation becomes locked. 每当显示操作表时,您就可以在Apple Notes应用程序中看到一个示例,方向会锁定。

I know you've already tried this and it works, I just think you should consider that as a valid solution. 我知道您已经尝试过了并且可以正常工作,我认为您应该将其视为有效的解决方案。

I'm not sure how to solve it otherwise, you would probably need to store any changes in orientation in your modal view controller and pass them back to the OpenGL view controller, either at the same time or once at the point of dismissing the settings view, then manually re-render. 我不确定如何解决此问题,您可能需要将方向的任何更改存储在模态视图控制器中,然后将其同时或在取消设置时一次传递回OpenGL视图控制器查看,然后手动重新渲染。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM