Fixed orientation issues on iOS8

I’m using the latest OF 0.9.0 nightly build 20150707 for iOS development.
I found some problems regarding rotation on iOS8 based on iosOrientationExample.

First, these were my settings in main.h to experiment.
(if I enable ‘enableHardwareOrientationAnimation’ then the rotation animation didn’t work properly. It just sways a little bit. I don’t know why there’s this setting)
settings.enableHardwareOrientation = true;
settings.enableHardwareOrientationAnimation = false;

With these settings, everything seemed to work well on iOS7, but I found the following issues on iOS8.

  1. When I build an app, it starts in a default orientation as it should be.
    but if I move a device a little bit(not rotating), it rotates to the current orientation unnecessarily.

  2. When I force to change the orientation using ‘ofSetOrientation’, It does rotate correctly from portrait to landscape mode but not from landscape to portrait mode. it still rotates, but to wrong coordinate so I could see a blank area in the top/right side of the screen.

  3. Once I force to rotate the device using ‘ofSetOrientation’, and then if I try rotating the device into the orientation that is already set, it should not rotate again as it is already rotated, but it rotates again.

I could fix the problem 1 and 2, but I could never fix number3. It seemed like the rotation is happening out side of ofxiOSViewController.mm. But I couldn’t find where it is actually happening.

So, these are the solutions I found at least for problem 1 and 2.

  1. In ofxiOSViewController.mm file, around line127, you will find “- (void)rotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation”.
    Inside the function, below “pendingInterfaceOrientation = interfaceOrientation;”
    add “currentInterfaceOrientation = pendingInterfaceOrientation;”

I don’t understand why it fixed the problem because there is already a code that does the same thing in line 216. but adding the code solved the problem anyway.

  1. Also in ofxiOSViewController.mm file, around line 166, you will find this section.

    if(UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) {
    center.x = screenSize.height * 0.5;
    center.y = screenSize.width * 0.5;
    } else {
    center.x = screenSize.width * 0.5;
    center.y = screenSize.height * 0.5;
    }

Replace the above code to the one below.

if( [[[UIDevice currentDevice] systemVersion] compare:@"8.0" options:NSNumericSearch] == NSOrderedAscending ) {
	if(UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) {
		center.x = screenSize.height * 0.5;
		center.y = screenSize.width * 0.5;
	} else {
		center.x = screenSize.width * 0.5;
		center.y = screenSize.height * 0.5;
	}
} else {
	center.x = screenSize.width * 0.5;
	center.y = screenSize.height * 0.5;
}

Then it will work properly when you force to change the orientation.
Now it should work well on both iOS7 and iOS8.
I would appreciate if someone could fix the problem 3 for the perfection.
Thanks!

can you open an issue in github? it’s easier for the ios developers to see it there.

ping @danoli3 @julapy

Thanks @cuinjune! In future definitely report this directly on the github issues. I’ll open an issue report for you linking here with proposed solution.

https://github.com/openframeworks/openFrameworks/issues/4154

1 Like

That’s awesome thanks! @danoli3