Search code examples
iphoneiosobjective-cdevice-orientation

How to set initial interface orientation?


My application always launches in landscape mode with the home button on the left side. If the home button on the right side it rotates. How do i make it opposite? I tried setting different values into info.plist file for initial interface orientation key but it didn't work. I tried switching order of values in this method:

- (NSInteger)supportedInterfaceOrientations
{
  return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskLandscapeLeft;
}

but it didn't work neither. How do i do that?


Solution

  • For IOS 5 and 5.1 :

    Try to set (BOOL)shouldAutorotateToInterfaceOrientation in your view controllers, it works for me.

    enter image description here

    enter image description here

        -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
        return toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight;
    }
    

    If you are using storyboards you can also set your initial and other viewcontrolers to landscape mode :

    enter image description here

    For IOS 6:

    your (NSInteger)supportedInterfaceOrientations should be (NSUInteger) , I am not sure though I never use it.

    // Only used by iOS 6 and newer.
    - (BOOL)shouldAutorotate
    {
        //returns true if want to allow orientation change
        return TRUE;
    
    }
    - (NSUInteger)supportedInterfaceOrientations
    {   
         //decide number of origination to supported by Viewcontroller.
         return return UIInterfaceOrientationMaskLandscape;
    
    
    }