Search code examples
iosobjective-cipadios6uiinterfaceorientation

Orientation issue in iPad ios6


I check the orientation of the device in viewDidAppear and viewWillAppear and force the orientation by calling willAnimateRotationToInterfaceOrientation method.

 - (void) viewWillAppear:(BOOL)animated
   {
     [super viewWillAppear:YES];
     _levelComplete = YES;

     [self willAnimateRotationToInterfaceOrientation:[[UIDevice currentDevice] orientation] duration:0.01];

   }

 - (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
  {
      if (toInterfaceOrientation == (UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight) )
     {

     }
     else  if (toInterfaceOrientation == UIInterfaceOrientationPortrait)
     {

     }
 }

The problem i face is that toInterfaceOrientation is remains 0 for both viewDidAppear and viewWillAppear method hence program crashes.

What might be the problem?

Please Help!


Solution

  • Try this

        - (void) viewDidLoad
           {
             _levelComplete = YES;
    
            [self adjustViewsForOrientation:self.interfaceOrientation];
    
           }
        -(void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation
       {
    
          if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown)
            {
    
            }
            else
            {
            }
     }