Question

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.

Was it helpful?

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.
}

OTHER TIPS

Can you be more clear? Are you wanting to allow orientation changes for some views and not for others? If you want to allow all rotation in iOS6, simply return yes for the function below in each viewController

-(BOOL)shouldAutoRotate
{
return YES;
}

The shouldAutoRotateToInterfaceOrientation method is now deprecated in iOS6.

Also, override the method below if you want to lock in certain viewControllers in an orientation.

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationPortrait;//whichever
}

If you want to allow orientation changes in some viewControllers, but not in others, you'll need override these methods in every base class and inherited class. You also have the option to use the NSNotificationCenter if you want to be notified of orientation changes and then manually trigger a view change. Let me know if you would like specifics on how to do that.

Hope it helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top