1

I'm making a universal app and I was wondering if it is possible to set initial orientation to Landscape for iPad and Portrait for iPhone? Currently, I'm setting initial interface orientation in the info.plist file but it doesn't seem to have different options for iPad and iPhone . If it cannot be done through info.plist file then how to do it programmatically?

tipycalFlow
  • 7,594
  • 4
  • 34
  • 45

3 Answers3

1

programatically you can do using following code -

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {

        if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
            return YES;
        } 

    }
    else {

        if (interfaceOrientation == UIInterfaceOrientationPortrait) {
            return YES;
        }
    }

return NO;

}

rishi
  • 11,779
  • 4
  • 40
  • 59
  • I found the solution here : http://stackoverflow.com/questions/402/iphone-app-in-landscape-mode – tipycalFlow Apr 13 '12 at 12:07
  • This is not the solution I was looking for, my friend...The issue is with launch orientation(when iOS has not begun with orientation notifications, so that `shouldAutorotateToInterfaceOrientation` is **not** called). If you `NSLog` the device orientation in your appdelegate, you'll get the output as `orientation unknown`!!! – tipycalFlow Apr 19 '12 at 05:15
1

It looks like the initial interface orientation property conflicts with the supported orientations. I found the solution here, though.

Community
  • 1
  • 1
tipycalFlow
  • 7,594
  • 4
  • 34
  • 45
0
    UIDevice* thisDevice = [UIDevice currentDevice];
    if(thisDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad)
    {
        [[UIDevice currentDevice] setOrientation: UIInterfaceOrientationLandscapeRight];
    }
    else
    {
        [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];
    }
mhunturk
  • 296
  • 2
  • 12