Supporting both iOS 6 and iOS 5 autorotation

12,714

Solution 1

You need to add new callback for autorotation if you are packaging your app in the new sdk. However, these callbacks will be received only when such an app is run on iOS 6 devices. For devices running on earlier iOS versions, earlier callbacks would be received. If you dont implement the new callbacks, the default behavior is that your app runs on all orientation on iPad and all except UpsideDown orientation on iPhone.

Solution 2

For iOS5 Rotation. Check for your desired orientation and return YES

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{  
    if ((interfaceOrientation==UIInterfaceOrientationPortrait)||(interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown)) {
        return YES;
    }
    else return NO;
}

iOS 6.0 Autorotation Support

- (BOOL)shouldAutorotate
{
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationIsPortrait(UIInterfaceOrientationMaskPortrait|| UIInterfaceOrientationMaskPortraitUpsideDown);

}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationIsPortrait(UIInterfaceOrientationPortrait|| UIInterfaceOrientationPortraitUpsideDown);

}

Solution 3

I think the most elegant solution is:

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    return ((1 << toInterfaceOrientation) & self.supportedInterfaceOrientations) != 0;
}

Do I miss something?

Solution 4

 - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationMaskAll;
}

-(void)viewWillLayoutSubviews
{
if([self interfaceOrientation] == UIInterfaceOrientationPortrait||[self interfaceOrientation] ==UIInterfaceOrientationPortraitUpsideDown)
    {
       if (screenBounds.size.height == 568)
        {
          //set the frames for 4"(IOS6) screen here
         }
        else

        {
         ////set the frames for 3.5"(IOS5/IOS6) screen here
        }

}
        else if ([self interfaceOrientation] == UIInterfaceOrientationLandscapeLeft||[self interfaceOrientation] == UIInterfaceOrientationLandscapeRight)
        {
         if (screenBounds.size.height == 568)
        {
          //set the frames for 4"(IOS6) screen here
         }
        else

        {
         ////set the frames for 3.5"(IOS5/IOS6) screen here
        }


    }
//it is for IOS5
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
     return YES;
    }

-(void)viewWillLayoutSubviews this method will call for ios5/ios6. this code is usefull to both ios6/ios5/ios6 with 3.5" screen/4" screen with ios6.

Share:
12,714
johnbakers
Author by

johnbakers

likes programming computers, but never studied it anywhere. asks a few good questions and a lot of dumb ones (i've actually learned more from the stupid questions). looks up to nearly all other programmers, regardless of their age.

Updated on June 05, 2022

Comments

  • johnbakers
    johnbakers almost 2 years

    Can anyone confirm that to support both iOS 6 and iOS 5 there is no point to adding the new iOS 6 autorotation methods, since the Apple docs suggest that these methods are completely ignored if you are also implementing the iOS 5 methods?

    In particular, I talking about the methods - (NSUInteger)supportedInterfaceOrientations and - (BOOL) shouldAutorotate -- that these are ignored and synthesized by the compiler if you also implement the - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation