Orientation is not updated on start-up

Hi, not sure if this is an OF0.8 bug or whether it’s my bug…

In the start of my app’s setup method I do this:

    ofSetOrientation(OF_ORIENTATION_90_RIGHT);

just to get a reference orientation which I base all my drawing coordinates on.

Then the only time I adjust the orientation from the app is here:

void myApp::deviceOrientationChanged(int newOrientation){

    if (newOrientation == OF_ORIENTATION_90_LEFT || newOrientation == OF_ORIENTATION_90_RIGHT) {
        DLog();
        
        ofSetOrientation((ofOrientation)newOrientation);

Now the problem is that when starting up it’s always in OF_ORIENTATION_90_RIGHT, even though I want it to be the same as the iOS orientation (either OF_ORIENTATION_90_LEFT or OF_ORIENTATION_90_RIGHT). That deviceOrientationChanged is not called and in the OF code I see that…

ofxiOSAlerts.deviceOrientationChanged(interfaceOrientation);

…is also not called.

So, to force an update, I tried editing this…

- (void)receivedRotate:(NSNotification*)notification {
	UIDeviceOrientation interfaceOrientation = [[UIDevice currentDevice] orientation];
    ofLogVerbose("ofxiOSAppDelegate") << "device orientation changed to " << interfaceOrientation;
	if(interfaceOrientation != UIDeviceOrientationUnknown && [self.glViewController isReadyToRotate] ) {
        ofxiOSAlerts.deviceOrientationChanged(interfaceOrientation);
    }
}

…to this…

- (void)receivedRotate:(NSNotification*)notification {
	UIDeviceOrientation interfaceOrientation = [[UIDevice currentDevice] orientation];
    ofLogVerbose("ofxiOSAppDelegate") << "device orientation changed to " << interfaceOrientation;
        ofxiOSAlerts.deviceOrientationChanged(interfaceOrientation);

}

And now it always seems to find the correct orientation on start-up, but am worried about any side-effects as that if-statement was clearly there for a purpose…

Any ideas?

Ok, have tested on:

  • iPad1 running iOS 5.1.1
  • iPad4 running iOS 7.1
  • iPad simulator running iOS 6.0

…and they all seem to be fine with this change…

If you want to support only landscape modes, then check only those in your xcode project

If you call ofSetOrientation() in the setup function, then it is going to set the orientation, as it should.
If you have enableHardwareOrientation enabled on the window (in main.cpp) then just call ofGetOrientation() in setup(). It will automatically set the orientation to the correct orientation.

Hi Nick,

This specific problem is not the supporting of landscape, but rather that it always starts in OF_ORIENTATION_90_RIGHT and I want it to automatically start up in either OF_ORIENTATION_90_RIGHT or OF_ORIENTATION_90_LEFT depending which way the iPad is facing on start-up.

After your reply I tried adding a ofGetOrientation(); at the end of my setup method, but no change.

However, the solution I posted above still works for me (also in OF0.8.1RC2).

Here’s my target general settings:

Here’s my plist:

Hmm. Now I see it happening on ios 7.1. OF doesn’t seem to get the correct orientation until after setup and update is called once. Not sure why? :confused:

I think receivedRotate is called during start-up, but the logic of the if-statement prevents it from invoking ofxiOSAlerts.deviceOrientationChanged(interfaceOrientation);