Search code examples
iphoneios6

Orientation issue in ios 6


I am working in universal app which works fine till ios 5 but in ios 6 there is orientation problem. My app is only in portrait mode. The problem is when my ipad is in landscape mode and than if i start my app than the orientation does nt change to protrait. So please help me with some code so that i force my app to be in protrait mode only independent of the orientation of device before the app launches


Solution

  • This is happening because Apple Has changed the Way of managing the Orientation of UIViewController. In Ios6 Oreintation handles Differently .in iOS6 containers (such as UINavigationController) do not consult their children to determine whether they should autorotate. By default, an app and a view controller’s supported interface orientations are set to UIInterfaceOrientationMaskAll for the iPad idiom and UIInterfaceOrientationMaskAllButUpsideDown for the iPhone idiom.So device getting orientation changed by default.

    So Need To Perform Some Steps.

    1 -Set the Orientation From Here

    enter image description here

    2 -Place This Code in FirstViewController added to the RootViewController

      @implementation UINavigationController (RotationIn_IOS6)
       //Here UINavigationController is the RootViewController added To the Window
    
     -(BOOL)shouldAutorotate
    {
    return [[self.viewControllers lastObject] shouldAutorotate];
    }
    
     -(NSUInteger)supportedInterfaceOrientations
    {
       return [[self.viewControllers lastObject] supportedInterfaceOrientations];
    }
    
     - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
    {
         return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
    }
    
    @end
    

    ** Put below methods in ViewController,Introduced In IOS6 Allow Oreintation Change**

      - (BOOL)shouldAutorotate
     {
    
       return NO;
    
      }
    
    /*Return the Number of Oreintation going to supported in device*/
    
     - (NSUInteger)supportedInterfaceOrientations
      {
    return  (UIInterfaceOrientationMaskPortrait |     UIInterfaceOrientationMaskPortraitUpsideDown );
    
     }
    
     // Returns interface orientation masks.
    
      - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
      {
          return  (UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown      ) ;
    
     }