【问题标题】:App only rotates in iOS 6 and not in iOS 5应用程序仅在 iOS 6 中旋转,在 iOS 5 中不旋转
【发布时间】:2012-10-27 12:52:14
【问题描述】:

我制作了一个针对 iOS 5 和 iOS 6 的应用程序,由于某种原因,它仅在运行 iOS 6 的设备上(无论是在 iPhone 还是 iPad 上)使用时才会旋转,并且不会在使用 iOS 5 的设备上旋转. 我的应用程序是通用的。请帮我解决这个问题!谢谢

【问题讨论】:

    标签: xcode ios5 ios6 xcode4.5 autorotate


    【解决方案1】:
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
    {
        return ((toInterfaceOrientation == UIInterfaceOrientationPortrait) || (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown));
    }
    
    - (NSUInteger)supportedInterfaceOrientations
    {
        return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
    }
    

    在所有 uiviewcontroller 子类中覆盖这两个方法......这适用于 ios 6 及更早版本

    【讨论】:

    • 注意这个例子只支持两种状态:'upright' (Portrait) 和'upside-down' (PortraitUpsideDown)。
    【解决方案2】:

    iOS 5 和 iOS 6 调用不同的方向和旋转代理。在 iOS 5 中,实现:

    shouldAutorotateToInterfaceOrientation:,在 iOS 6 中已弃用。

    因此,在 iOS 6 中,请确保您设置了根视图控制器,并实现:

    shouldAutorotate:、supportedInterfaceOrientations 和supportedInterfaceOrientationsForWindow:

    【讨论】:

      【解决方案3】:

      我遇到了类似的问题。你可以查看这个问题的答案:

      Rotation behaving differently on iOS6

      总而言之,要让自动旋转在 iOS 5 和 iOS 6 中充分发挥作用,并且还要处理 PortraitUpsideDown 方向,我必须实现一个自定义 UINavigationController 并将其分配给应用程序委托 didFinishLaunchingWithOptions 方法中的 self.window.rootViewController

      【讨论】:

        【解决方案4】:

        shouldAutorotateToInterfaceOrientation 在 ios6 中已弃用。

        所以如果你想在两个操作系统版本上运行应用程序,那么也添加 shouldAutorotateToInterfaceOrientation 如下

        //for ios6
         - (BOOL)shouldAutorotate {
        
                UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
        
                if (orientation == UIInterfaceOrientationLandscapeLeft  ||orientation ==  UIInterfaceOrientationLandscapeRight ) 
        {
        
                    return YES;
                }
                return NO;
                }
        
        //for ios5
        
        - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
            //interfaceOrientation == UIInterfaceOrientationLandscapeRight; 
            if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft  ||interfaceOrientation ==  UIInterfaceOrientationLandscapeRight ) {
        
                return YES;
            }
            return NO;
        }
        

        【讨论】:

          【解决方案5】:

          为了在 ios5 和 ios6 中支持自动旋转,我们需要在 ios6 的情况下提供回调......`[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

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

          我们需要打电话

          - (NSUInteger)supportedInterfaceOrientations {
          return UIInterfaceOrientationMaskPortrait;
          

          }

          -(BOOL)shouldAutoRotate{
              return YES;
            }
          

          ios5

          - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
          

          { return ((toInterfaceOrientation == UIInterfaceOrientationPortrait) || (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)); }

          【讨论】:

          • 嗯...我不是已经格式化了吗?不,这是另一个副本:所以请不要对多个问题发布完全相同的答案:它要么不适合所有人,要么问题是重复的,应该这样标记/关闭。
          猜你喜欢
          • 2014-12-07
          • 2012-10-01
          • 1970-01-01
          • 2012-09-08
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2023-03-15
          • 1970-01-01
          相关资源
          最近更新 更多