iOS8 wrong device orientation in the beginning

Hi, I’m using the latest version of nightly build 0628.

I’ve been struggling with the device orientation problem in iOS8.
My old project still runs well on iOS7 but not iOS8.
And I found out the problem was that it gets wrong(opposite) value ofGetWidth() and ofGetHeight() in the setup().
Here’s my example code to simply test the orientation.

in main() //regarding orientations.
settings.enableHardwareOrientation = true;
settings.enableHardwareOrientationAnimation = false;

in ofApp.h

int deviceWidth, deviceHeight;

in ofApp.mm

setup() {

deviceWidth = ofGetWidth();
deviceHeight = ofGetHeight();

 cout << deviceWidth << "  " << deviceHeight << endl;

}

draw() {

ofSetColor(255, 0, 0);
ofDrawCircle(deviceWidth / 2, deviceHeight / 2, 100); //Draw a red circle in the center of the screen

}

If I run the code in the Simulator, sometimes it works depending on the orientation of Simulator before I build it. It seemed to be working well on iPhone Simulators but not on iPad Simulator, sometimes I could see circle placed somewhere else and not center. And in my real device which is iPad air2, it didn’t work either. I think it is affected by the orientation of the device before I build it.

If I use iOS7 SDK, the above code always worked well regardless of the orientation of the device before the build.

I would appreciate if someone could please fix this.
And sorry, I don’t know how to post the issue on github yet.
Thank you!

Have you tried the iosOrientationExample? I have tested that.
This code works fine for me.

But the rotation animation still has a problem. A blink (or disappear ?) of the shapes in draw() occur at the beginning of rotation-animation start.

in draw()

ofSetColor(255, 0, 0);
ofDrawCircle(ofGetWidth() / 2, ofGetHeight() / 4, 20); //Draw a red circle in the center of the screen
ofDrawCircle(ofGetWidth() / 2, ofGetHeight() / 2, 100); //Draw a red circle in the center of the screen

in deviceOrientationChanged(int newOrientation)

    ofSetOrientation((ofOrientation)newOrientation);
1 Like

Thank you!

Yes, I have tried iosOrientationExample and it works for me.

And also, your code works for me as well.

It’s just that on iOS8, it doesn’t return the correct dimension in the setup().

If I check ofGetWidth(), ofGetHeight() in update() or draw(), it returns correct value.

On iOS7, it always returned correct value even from setup().

If you don’t know what I mean, please try my code above.

You are right.

I have checked other function.
The “ofGetOrientation()” function will be working in setup() and in deviceOrientationChanged(int newOrientation).

This code is just a trick.

#include "ofApp.h"

//--------------------------------------------------------------
void ofApp::setup(){	

    if(ofGetOrientation()==3||ofGetOrientation()==4) {
        deviceWidth = ofGetHeight();
        deviceHeight = ofGetWidth();
    } else {
        deviceWidth = ofGetWidth();
        deviceHeight = ofGetHeight();
    }
    
}


//--------------------------------------------------------------
void ofApp::draw(){
	
    ofSetColor(255, 0, 0);
    ofDrawCircle(deviceWidth / 2, deviceHeight / 4, 20);
    ofDrawCircle(deviceWidth / 2, deviceHeight / 2, 100);
    
}


//--------------------------------------------------------------
void ofApp::deviceOrientationChanged(int newOrientation){

    ofSetOrientation((ofOrientation)newOrientation);
    
    deviceWidth = ofGetWidth();
    deviceHeight = ofGetHeight();
    
}
1 Like

That’s a great trick!
Thank you very much for your help :smiley:

I still hope somebody could fix this issue in an OF level so one doesn’t have to do the trick.