Weird issues with rotation when porting 007 app to 0073

Hey all,

I have an app I made for iPhone in OF007 and had tried to port it to iPad a while back but left it aside. I’m now trying to get my app working in iOS6 and 0073 but it’s giving me some weird issues with how it handles rotation and the display of my gui view.

For some reason when I open the app with 0073 it takes the whole window and turns it sideways and chops off a portion near the home button. My iOS gui view also won’t display on the top of the screen as I normally have it (originally taken/modified from the gui example).

Does anyone know significant changes that happened to the ofcore Eaglview handler and stuff like that that I should look at that might be causing this?

The code is mostly unchanged and should work the same, but the only way I can get it to stop rotating is if I make the ‘portrait’ view the only supported orientation.

I can always keep the port with 007 but would love the option to upgrade a bit.

Thanks as always!

Can’t say I’ve seen that specifically, but note that rotation has changed if you’re building with the iOS6 SDK. See the top answer here http://stackoverflow.com/questions/12536645/rotation-behaving-differently-on-ios6

I had to make all those changes for my oF project (actually built on a modified 0062 core, but should still apply) to rotate properly on iOS6.

I believe in 0073 the way you add the gui view is now slightly different. There’s a new view that was added. Check out the GUI example in 0073 and you’ll see how it’s added now.

I’m not 100% that’ll fix the rotation issue.

hi, laserp. it’s an ios6 thing. Apple is evil… the shouldautorotate method of UIViewController is now deprecated. so it doesn’t work on ios6 (…)

newest version of OF has an example named iosNativeExample that handles the gui views differently. It’s a very cool example…

I had the same problem with my AVPlayer’s wrapper autorotation… I ended up creating a new object… suitable with apple’s new vices. I can share it if your problem is related with playing videos on 007, it’s a bit rough around the edges but it does the job… (plays videos / draws videos in smaller size on screen… and auto-rotates)

I actually think I’m running into this same problem now. Did you figure it out?

I’m able to rotate, but now it rotates the full OF openGL (thus cutting a portion of it off since it doesn’t resize) instead of just the view on top.

If I put the supported InterFace Orientations to portrait only, then it keeps the openGL from rotating, however now the GUI view won’t rotate.

The way my app worked before was the openGL view would never rotate and I would rotate a native GUI on top of it to all orientations. I’m not seeing how it’s possible to keep openGL the same and still be able to rotate a top view.

I had the same problem, it’s an ios6 thing, they deprecated the shouldautorotate function from UIViewController the way you fix it is find the part of your code that used that shouldautorotate fuction in obj-c code and you fix it by changing the obj-c code.

visit these links:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController-Class/Reference/Reference.html#//apple-ref/occ/instm/UIViewController/preferredInterfaceOrientationForPresentation

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController-Class/DeprecationAppendix/AppendixADeprecatedAPI.html

![](http://forum.openframeworks.cc/uploads/default/2687/Screen Shot 2012-12-13 at 18.36.02.png)

![](http://forum.openframeworks.cc/uploads/default/2689/Screen Shot 2012-12-13 at 18.36.14.png)

![](http://forum.openframeworks.cc/uploads/default/2691/Screen Shot 2012-12-13 at 18.38.02.png)

Thanks kkkkkkkk.

The thing is, it doesn’t seem as simple as changing all the shouldAutorotateToInterfaceOrientations because they also changed it so that only the root view controller gets the call. So, subviews and subview controllers don’t get notified it seems. So, the root view has to cycle through the sub views controllers to see if they allow it, but I haven’t found a simple way to do that using OF.

So far I’ve been unable to figure out a solution for being able to keep the openGL view to not rotate while allowing a UIkit view on top of it able to rotate.

I know what you mean, I had the same problem exactly, but the problem is I think that deprecated function initially I tried to replace it like in the screenshots… but I couldn’t make it work in OF…

nevertheless in my case when I replaced AVPLAYER with MPMoviePlayerController for some reason that thing worked so I called it a day… … I tried to look into the code of MPMoviePlayerViewController.m to figure out why it works and the other doesn’t but I couldn’t find the file inside the framework…

![](http://forum.openframeworks.cc/uploads/default/2693/Screen Shot 2012-12-13 at 19.13.59.png)

![](http://forum.openframeworks.cc/uploads/default/2694/Screen Shot 2012-12-13 at 19.14.13.png)

ofxMPMoviePlayerController.zip

Are you using presetnViewController to show the video controller?

If so, that may be why it works, although I need to look into it. If it’s present as a modal then I think it counts as the top/root, but for example if you want to overlay just a GUI (not presented as a modal) then the autoRotate functions won’t be called.

Thanks for the help everyone…I ended up keeping it in 0071 for the time being, but this is useful if I touch the code again

hi guys, so I sat again down to figure out how to make the auto-rotation work on ios6+0073 and I used the “iosNativeExample”

so… long story short it works… but you need to tweak OF ofxiPhoneViewController obj-c class inside ofxIphone

in general here is how you fix the rotation problem in ios6 & OF:

you find the deprecated function

  
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {  
  

in your obj-c code

and you paste bellow it :

  
  
-(BOOL)shouldAutorotate  
{  
      
    return [[self.navigationController navigationController] shouldAutorotate];  
}  
  
-(NSUInteger)supportedInterfaceOrientations  
{  
    return [[self.navigationController navigationController] supportedInterfaceOrientations];  
}  
  
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation  
{  
    return [[self.navigationController navigationController] preferredInterfaceOrientationForPresentation];  
}  
  
  

you must do this for every ofxiPhoneViewController you have or every UIViewController

if you want them to respond to the rotation you should paste the above code below the deprecated function

* you can leave the function there to support ios5 (I am not sure if this is going to need a precompiler if statement you need to test it on ios5 but It works on ios6 so…)

and yeah that’s it.

also in case you have problems like not compiling or not rotating

GO:

inside your app delegate (your ofxiPhoneAppDelegate interface)

inside the .mm file

inside the - (BOOL)application:

AND:

you MAKE SURE

your viewController is a root controller

like this:

  
  [self.window setRootViewController:self.navigationController];  
  

or this:

  
    self.window.rootViewController = self.navigationController;  

Below I attached the example but to solve the cropping problem you need to modify stuff inside the

ofxiPhoneViewController object (@interface) in the ofxIphone core

So go inside openframeworks > ios+OFLib.xcodeprj > addons >ofxiPhone > src > core > ofxiPhoneViewController.mm

inside the

  • (id)initWithFrame:(CGRect)frame app:(ofxiPhoneApp *)app {

if((self = [super init])) {

ADD: after the self.glView.delegate=self;

  
        self.glView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;  
  

this solves the problem but you need to modify it on your own OF

iosNativeExample.zip

1 Like

Awesome! kkkkkkkks solution works for me (IOS6, of073). Thanks!

Hi, just running into the same problem… but not using the iosNativeExample as a base, so having some trouble applying the fix to more generic OF code.

e.g. this fix:

  
    -(BOOL)shouldAutorotate    
    {    
            
        return [[self.navigationController navigationController] shouldAutorotate];    
    }    
        
    -(NSUInteger)supportedInterfaceOrientations    
    {    
        return [[self.navigationController navigationController] supportedInterfaceOrientations];    
    }    
        
    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation    
    {    
        return [[self.navigationController navigationController] preferredInterfaceOrientationForPresentation];    
    }    
  
  

…in the standard ofxiPhoneViewController.mm it’s just a subclass of the standard UIViewController, so I guess self.glView would be the equivalent of self.navigationController, but unsure what to pass to it.

And moreover not really sure what the above example is passing back… it’s just calling its parent navigationController, right? But where are the orientation limitations actually set - only in the plist?

Basically the problem is now that the co-ordinate system seems really messed up to how it was in iOS5.1 and we have to put ifdefs all over the shop to check for iOS 6 vs iOS 5… which doesn’t seem right… :-\

But: The cropping fix seemed to work fine btw - nice one! :slight_smile:

Cheers for any tips!

Hi, Gwydion!

I do sense your frustration, … … they just removed that function from ios6 and now if you want to support autorotation in ios6 you just need use the new one… (apple in a nutshell for you)

… I just used the iosNativeExample Here as a generic example of how to deal with this issue so everybody can understand what the basic changes are…
I actually had to deal with variations of this thing on other cases with different objects …

in general it’s
3 generic changes: a the above code below the deprecated function… (note that this code can be different according to your case if I recall correctly in the iosNativeExample you just need to declare it no need to call it somewhere else… but in other cases you have to… (I don’t have OF on my machine right now I have made another example where I autorotate a video that does what I described) by the end of the week I will be able to upload it here

b: MAKE SURE your viewController is a root controller c: the cropping issue…

basically all UIViewControllers have this issue now so… a lot of complimentary addon stuff in OF that used UIViewController class or ofxiPhoneViewController subclass will now have rotation issues in ios6.

But the core of OF (like what’s inside your draw in test-app) uses a different method to rotate things that still works in ios6!

…what do you want to “autorotate”?

Thanks for getting back to me.

We need to rotate the OF view in all its full GL glory, the basic ofxiPhone UIViewController (so that, for example, the iOS keyboards appear with the correct rotation), plus an independent UIViewController that appears on top of the glView…

I think the setting of the root controller is already in the default OF 0073 iPhone add on package, so that should be fine.

I was just wondering with your code snippits - somewhere you have to set what orientation is supported and what isn’t - where do you do that, just in the plist?

yeah, basically it’s in the plist! you set it up from x-code…

  
<key>UISupportedInterfaceOrientations</key>  
	<array>  
		<string>UIInterfaceOrientationLandscapeLeft</string>  
		<string>UIInterfaceOrientationLandscapeRight</string>  
		<string>UIInterfaceOrientationPortrait</string>  
	</array>  

but ofcourse you can rotate things programatically

before jumping into more complicated stuff
… have you tried something like:

  
    if(ofxiPhoneGetDeviceOrientation() == UIDeviceOrientationLandscapeLeft){  
        ofxiPhoneSetOrientation(OFXIPHONE_ORIENTATION_LANDSCAPE_LEFT);  
          
    }  
 if(ofxiPhoneGetDeviceOrientation() == UIDeviceOrientationLandscapeRight){  
        ofxiPhoneSetOrientation(OFXIPHONE_ORIENTATION_LANDSCAPE_RIGHT);  
          
          
    }  

and then call the updateOrientation function from ofxiPhoneKeyboard.mm

The keyboard should be a separate issue only if it uses a new UIViewController on top of our OF window…

thing is… I’ve downgraded from m.lion the otherday… and went back to sweet old love Snow-leopard and I cannot really use Ios6 SDK to test things anymore… so I can’t really give you a clean solution on your problem beside brainstorming ideas… because I can’t test things on my machine…
:frowning: sorry about that…

I’ve been working with kkkkkkkk’s fix with the latest OF release as well as ddf’s fix with version 007: http://code.compartmental.net/2012/01/13/auto-rotation-in-ios-with-openframeworks/

I’ve slowly been chipping away at each, and using part of kkkkkkkk’s fix has made this overall solution work for 007. Whereas kkkkkkkk does this in 0073:

In 007, after implementing ddf’s fix, I do this: In /openFrameworks/addons/ofxiPhone/src, open ofxiPhoneAppDelegate.mm

Inside:

  
 -(void) applicationDidFinishLaunching:(UIApplication *)application {}  

Under the line:

  
 [window addSubview:glView];  

Add the line:

  
 self->glView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;   

(Maybe there’s a better place to add this line in the method, but it works).

Now, my issue with the 007 fixis with the rotation animation. I have a circle in the middle of the screen, and it occupies the same space whether the orientation is portrait or landscape. So when I rotate the device, I want the circle to rotate from its center point (also the center of the device). Instead, it rotates into place from some odd point off to the side, so the animation isn’t clean. I can turn animation off, but I like the animation. Is there some fundamental setting, or something I’m missing for the OF window and my UIViewController to rotate on the center point of the app/device? I figure it must have something to do with how I’ve sized my views, but since everything does actually rotate into place (albeit sloppily) I’m having a lot of trouble solving this.

I would prefer to use the 0073 fix, but my problem is this: I took one of the apps in iosNativeExample - the Circle app - and put my OF code in CircleApp.h and CircleApp.mm. I put all my view controller stuff in CircleAppViewController.h/.mm and added a nib file. When I fire up the app and select the Circle app from the menu, my OF window rotates nicely with the navigation bar, but the view controller doesn’t rotate. I have added all the new ios6 rotation methods as recommended by kkkkkkkk. I’ve added the Circle view controller to CircleApp.mm as a subview as such:

  
     myGuiViewController	= [[CircleAppViewController alloc] initWithNibName:@"CircleAppViewController" bundle:nil];  
     [ofxiPhoneGetUIWindow() addSubview:myGuiViewController.view];  

Anyone know how I can get the view controller to “be a part of” the rest of the app?

Hi josh,

what SDK do you have?
This solution is for ios6 SDK+OF (007+0073)
can’t tell you forsure because I’ve deleted ios6 from my laptop…
but I think your problem can be solved by setting the center point of what you add in the subview?

  
 CGPoint p;  
    p = ofxiPhoneGetGLView().center;  
    myGuiViewController.center = p;  

Wow, I’m halfway there! I added your code, modifying the last line to:

  
myGuiViewController.view.center = p;  

and now it rotates beautifully when switching from landscape left to landscape right or vice versa.

Still no luck when switching to/from portrait. I think this might be because the way I have this set up, deviceOrientationChanged is not firing, so I’m unable to update the screen width and height. By the way I’m using SDK 6.1. Is deviceOrientationChanged one of the things I lose when I run this kind of setup in iOS 6?

hey

just wondering if there is a definite working fix for this?

@kkkkk

but you need to tweak OF ofxiPhoneViewController obj-c class inside ofxIphone
in general here is how you fix the rotation problem in ios6 & OF:
you find the deprecated function
Code:

  • (BOOL) shouldAutorotateToInterfaceOrientation:

not seeing it here:
https://github.com/openframeworks/openFrameworks/blob/master/addons/ofxiPhone/src/core/ofxiPhoneViewController.mm

what am i missing?

thanks!