Question about iOS rotation

Under normal circumstances, the right side should be displayed but it doesn’t.I was troubled by the OF_iOS’s rotation.

I tried to set the orientation, but all black on the right side of the screen .

ofSetOrientation(OF_ORIENTATION_90_RIGHT);

I also enable the hardware orientation.

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

The photo below is the nomal one.

What I want is an app with a locked landscape mode not the photo up there with a portrait mode, but it seems there is something I don’t understand.

I have generate the same project on my retina MacBook Pro. And it looked okay.

Anyone can help?

I am not sure if theres a better way to do this now… but this is how I have done it in the past. You need to reposition all the elements for each orientation.

.h add these functions

    void rotateToPortrait();
    void rotateToPortraitUpSideDown();
    void rotateToLandscapeLeft();
    void rotateToLandscapeRight();
    void toggleAutoRotation();

.cpp

   void ofApp::setup(){
    
    //change bg
    ofBackground(60, 60, 260);
    
    //set default orientation
    ofSetOrientation(OF_ORIENTATION_DEFAULT);

}

//--------------------------------------------------------------
void ofApp::update(){
    
}

//--------------------------------------------------------------
void ofApp::draw(){
    
    string currentOrientation = "";
    
    //make string and change bgcolor for different orientations
    switch (ofGetOrientation()) {
        case OF_ORIENTATION_DEFAULT:
            currentOrientation = "Portrait";
            break;
        case OF_ORIENTATION_180:
            currentOrientation = "Portrait Upside Down";
            break;
        case OF_ORIENTATION_90_LEFT:
            currentOrientation = "Landscape Left";
            break;
        case OF_ORIENTATION_90_RIGHT:
            currentOrientation = "Landscape Right";
            break;
        default:
            break;
    }
    
    //output string
    ofDrawBitmapString("current orientation is", 20, 20);
    ofDrawBitmapString(" > " + currentOrientation, 20, 40);

}
//--------------------------------------------------------------

void ofApp::rotateToPortrait() {
    ofSetOrientation(OF_ORIENTATION_DEFAULT);

    /////////////////////////////
    // set XY for each object here
    /////////////////////////////

}

void ofApp::rotateToPortraitUpSideDown() {
    ofSetOrientation(OF_ORIENTATION_180);

    /////////////////////////////
    // set XY for each object here
    /////////////////////////////

}

void ofApp::rotateToLandscapeLeft() {
    ofSetOrientation(OF_ORIENTATION_90_LEFT);

    /////////////////////////////
    // set XY for each object here
    /////////////////////////////

}

void ofApp::rotateToLandscapeRight() {
    ofSetOrientation(OF_ORIENTATION_90_RIGHT);

    /////////////////////////////
    // set XY for each object here
    /////////////////////////////

}

After added your code, it seemed better.But still have some problem.

For the first time I open the app with portrait mode(default), but the result it displayed was showed in picture 1.

Only when I rotate my iPad to landscape mode then turn it back to portrait mode, the app is going to display correctly. I have not idea about that.

Hey @BentleyJobs maybe you can trying forcing it into portrait in setup(). Try replacing

ofSetOrientation(OF_ORIENTATION_DEFAULT);

with

rotateToPortrait();
1 Like