2
votes

I have an OpenGL app which supports dynamic device orientation. I can rotate the device to any of the 4 physical orientations and everything works as expected.

Now I've added a modal view controller so that you can get a settings view (this is non-OpenGL). The modal view controller also supports any device orientation.

However, if I present the modal view controller in orientation A (e.g. portrait) and dismiss it in orientation B (e.g. landscape-right), after it is dimissed, the OpenGL view is corrupted (the aspect ratio looks wrong). I have to orient the device to a different orientation for the OpenGL view to 'correct' itself.

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.

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.

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?

Thank you.

1
Which mechanism are you using to detect rotation changes in order to update you OpenGL view? What manages the presentation of that OpenGL view which might adjust its frame? - Jonah
shouldAutorotateToInterfaceOrientation for the OpenGL view controller returns YES. willRotateToInterfaceOrientation is called on the OpenGL view controller. layoutSubviews is called on the OpenGL view, which releases the OpenGL buffers. Next time the render function is called, the OpenGL buffers are re-created with a swapped width/height. - iraxef
How did you get it working when the modal is fixed in portrait? I ahve the same problem with just that - jfisk

1 Answers

1
votes

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.

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.