Adam Storr
Adam Storr

Reputation: 1450

Cannot Detect Orientation on Load -- iPad

I've gone through many different questions and for some reason, I still cannot get my iPad to detect orientation on load.

It seems like the best way to do this is by detecting the statusBarOrientation:

- (void)viewDidLoad {
    [super viewDidLoad];
    NSLog(@"View Loads");

    if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft
        || [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight) {
        NSLog(@"This is Landscape"); 
    } else {
        NSLog(@"This is Portrait"); 
    }
}

But it always returns "Portrait". I have all 4 orientations available in my .plist and shouldAutorotateToInterfaceOrientation set as well:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
        return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || 
                interfaceOrientation == UIInterfaceOrientationLandscapeRight || 
                interfaceOrientation == UIInterfaceOrientationPortrait);        
        } else {
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }
}

Does anyone have any other advice? Thanks in advance!

Upvotes: 3

Views: 489

Answers (1)

MusiGenesis
MusiGenesis

Reputation: 75296

iPad apps always start in portrait mode, regardless of the actual device orientation (they're then immediately rotated to landscape if that's what the device is on). If you check the status bar orientation later in the program lifecycle with the same code, you'll see that it returns the actual orientation.

Upvotes: 4

Related Questions