views:

281

answers:

2

Like many people, I have a splash screen that animates off to reveal the first view of my app. I've been reworking this for the iPad and if you are holding the device in portrait or landscape modes, everything works as intended, the correct default image is used, the correct image that is used to animate this off is used, all orientations work fine.

BUT

If I get the device into landscape mode, and then lay it flat on the table, things go wrong. The correct splash screen is used, but the image used to animate it off is wrong and I have traced this to the following code which is returning 5 - ie none of the portraitupsidedown / portrait / landscapeleft /landscaperight modes that it is meant to return.

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
UIInterfaceOrientation orientation = [UIDevice currentDevice].orientation;

The device itself clearly knows the correct orientation to use as the status bar is correct and indeed the first view controller rotates into the correct orientation - but what is clear is that [UIDevice currentDevice].orientation is not the same as the device actually knows and so the code I am using to deploy appropriate graphics inside the app delegate is wrong.

I guess my question is - how can I fix this? Is there a way of getting the correct device orientation within the app delegate?

+1  A: 

The UIInterfaceOrientation is a subset of the UIDeviceOrientation. If UIDeviceOrientationIsValidInterfaceOrientation is false, then you can assume usually UIInterfaceOrientationPortrait. Besides checking the device orientation, you can also check the statusBarOrientation of UIApplication, but at startup it may not have a valid value either.

drawnonward
Ah, didn't know about the IsValidInterfaceOrientation, that's useful. Interestingly if I use the statusBarOrientation in the app delegate, that gives me a valid direction, but the WRONG one - as you say it seems that on startup the orientation isn't being communicated to the app delegate yet. Most perplexing ... looks like I'll need to restructure things :-(
Roger
A: 

I'm having the same issue, with a game. I have read that using a ViewController and responding to - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation helps, but i don't have a ViewController. Have you managed to work around this issue?

DavidG
I am using shouldAutorotate... and I get weird behaviors in flat mode too.
amok