views:

495

answers:

1

Greetings,

This question does seem to be an ongoing saga in the world of iphone SDK... so heres my contribution...

Had two separate projects from the same template... one semi-works, the other not at all... Please let me explain my steps...

used this basic GL ES template //iphonedevelopment.blogspot.com/2008/12/opengl-project-template-for-xcode.html had to sort out some of the 'Release' configuration but otherwises has eveything I need to add orientation to a GL ES project.

One my first project, did my stuff, then added these methods....

-(BOOL)shouldAutoRotateToInterfaceOrientation .....   
-(void)willRotateToInterfaceOrientation ....
-(void)didRotateFromInterfaceOrientation ....
-(void)willAnimateRotationToInterfaceOrientation ....

And understand what they do (or are trying to do in my case), the (BOOL)should... gets called once when the view controller is created, and returns 'YES'. But after that none of the other methods are called!

So I started from scratch with a blank template (GL ES one from above)...and added minimum to support auto rotation. But this time none of the methods get called!

So I investigated .... //developer.apple.com/iphone/library/qa/qa2010/qa1688.html as it said, I added the GLViewController.view first, then added the GLview as subviews of the application delegate. Nothing!

Then found this //www.iphonedevsdk.com/forum/iphone-sdk-development/44993-how-determine-ipad-launch-orientation.html which states to enable orientation notifications

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

and then subsequently disable them in the view controller... makes sense...did it, nothing...

I think the notifications might be on by default though, since I didn't need to enable them in the first project, yet it still try to verify a orientation (i.e (BOOL)shouldAutoRotate... )...

If any one could help me out it would be greatly appreciated as this issue is driving me insane. Thanks in advance.

The code can be found here ... http://rapidshare.com/files/392053688/autoRotation.zip

N.B These projects avoid nib/xib resources, would like to keep it that way if possible.

P.S iPad device not out where I am so I cannot test on a device yet. Would be nice for it to work on the simulator.

+1  A: 

Ok.. so after another couple head butts against the wall, tried doing it manually ... hallelujah ...

so here's the result ... add these two lines so they called when the view controller gets created ... i.e in -(void)loadView or equivalent

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selectot(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];

and set (void)should.... to return YES

-(void)shouldRotateToInterfaceOrienation
{
return YES;
}

remove all..

-(void)willRotateToInterfaceOrientation ....
-(void)didRotateFromInterfaceOrientation ....
-(void)willAnimateRotationToInterfaceOrientation ....

these aren't needed...

and then add a method called didRotate

-(void)didRotate:(NSNotification*)notification
{
UIDeviceOrientation oreo = [[UIDevice currentDevice] orientation];
// oreo is our new orientation!
}

basically, the issue was that I did a half arsed attempt to get it working with the beginGeneratingDeviceOrientationNotifications addition. I also needed to 'capture' the orientation events and process them myself...

For the purists that want to know why? I don't know or understand why, sorry... in theory it should have worked, but in practice did not.

capple