Supporting both iOS 6 and iOS 5 autorotation

后端 未结 6 1369
-上瘾入骨i
-上瘾入骨i 2020-12-06 05:46

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 c

相关标签:
6条回答
  • 2020-12-06 06:16

    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?

    0 讨论(0)
  • 2020-12-06 06:23
     - (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.

    0 讨论(0)
  • 2020-12-06 06:31

    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.

    0 讨论(0)
  • 2020-12-06 06:38

    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);
    
    }
    
    0 讨论(0)
  • 2020-12-06 06:38

    to support autorotations in both ios5 and ios6 we need to provide call backs in case of ios6....

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(orientationChanged:) 
        name:UIDeviceOrientationDidChangeNotification object:nil];
    

    and we need to call

    - (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
    
    } 
    
    -(BOOL)shouldAutoRotate{
        return YES;
      }
    

    for ios5

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
    {
    return ((toInterfaceOrientation == UIInterfaceOrientationPortrait) || (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown));
    }
    
    0 讨论(0)
  • 2020-12-06 06:43

    You have to set a flag somewhere (I believe in your Info.plist) that indicates which of the two you use. If you use the new one, you can't build for iOS 5 (or at least, it won't work on iOS 5). If you use the old one, the new methods aren't being called. So yeah, you pretty much have to choose which method(s) you want to use, and if you want to support iOS 5, you cannot use the new methods.

    0 讨论(0)
提交回复
热议问题