Problems with OF0.8 + orientation

Hi,

I’m trying to migrate from OF0.7 to OF0.8 and running into a few problems with the new orientation code:

  1. What’s the correct way to limit the orientations supported?
  2. My UIView responds slightly differently compared to the GLView which means they get out of sync - how to fix?
  3. Start-up orientation is never as expected - how to get it to start-up in the iPad’s current orientation correctly?

More details:

I want it to just support the two landscape orientations, and not the two portrait orientations. My plist has these two entries as shown:

My main.mm enables the rotation support…

int main(){

ofAppiOSWindow * iOSWindow = new ofAppiOSWindow();

iOSWindow->enableHardwareOrientation();
iOSWindow->enableOrientationAnimation();

…and in my application file, I respond to rotation thus:

void myApp::deviceOrientationChanged(int newOrientation){

ofSetOrientation((ofOrientation)newOrientation);

Do I need to alter this?

Currently, what appears to happen is that the GLView rotates all the time to all orientations. It also rotates back to Portrait whenever it gets an “unknown orientation” status (5) which is when it gets out of sync with the UIView. Ideally, when getting the Unknown Orientation it should do nothing (i.e. keep the current orientation).

Thanks for any advice…

Gwydion

I just tried the following:

void myApp::deviceOrientationChanged(int newOrientation){

if (newOrientation != 5) {
    ofSetOrientation((ofOrientation)newOrientation);

…and that seems to make things a lot better. Just wondering if that’s ok though… shouldn’t this “not rotating back to portrait when unknown” be handled in the OF lib level rather than in my app?

Ok, have found answers to all my own questions above :smile: so will post here in case it helps anyone:

For iOS 6 and 7 I found that it was fine to put the check in my app’s deviceOrientationChanged method, like this:

void myApp::deviceOrientationChanged(int newOrientation){

    if (newOrientation == OF_ORIENTATION_90_LEFT || newOrientation == OF_ORIENTATION_90_RIGHT) {

        ofSetOrientation((ofOrientation)newOrientation);

    }

}

However, for iOS 5, this did not do enough and I had to edit the OF code’s ofxiOSViewController.mm file, changing…

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    return (toInterfaceOrientation == currentInterfaceOrientation);
}

…to…

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
                return (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

I seemed to have to do this here as any shouldAutorotateToInterfaceOrientation in my app’s UIViewControllers were ignored.

In addition to this I had to remove all the rotation code from the ofxiOSKeyboard.mm - otherwise the text field orientation got out of sync sometimes too. I can post the full changes if needed.

Finally, to get the start-up orientation working correctly, see here: Orientation is not updated on start-up