Search code examples
ios6frameorientation-changesios5

Orientation in iOS


I am new to orientation. I wish to know how to implement orientation in iOS. Now that the method used is different for both iOS5(and below) and iOS6.

Should the frame of all objects be set differently in 4 types(PortraitUpsideDown,Portrait,Landscape left,Landscape right)?

I tried

-(BOOL)shouldAutoRotate
{
return YES;
}

But it is not working.


Solution

  • This is the code that helped me. Thanks for all your help.

    - (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
         //Only iOS5 and below
         return YES;
    }
    
    
    - (BOOL)shouldAutorotate {
         //Only iOS6
         return YES;
    }
    
    - (NSUInteger)supportedInterfaceOrientations {
         //Only iOS6
         return UIInterfaceOrientationMaskAll;
    
    }
    
    
    -(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    
         //iOS6 and below
    
         if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight ) {
              [self landscapeView];
    
         }
         else {
               [self portraitView];
        }   
    }
    
    
    -(void) portraitView {
    //Set the portrait frames here.
    }
    
    
    -(void) landscapeView {
    //Set the landscape frames here.
    }