【问题标题】:orientation issue iOS 5方向问题 iOS 5
【发布时间】:2013-05-24 12:12:35
【问题描述】:

我创建了一个只支持landscape orientation(左和右)的 iPad 应用程序。Ìt 在iOS 6 上完美运行,但在iOS 5 上,应用程序被打开了。

谁能帮我解决这个问题。

【问题讨论】:

标签: ios objective-c uiinterfaceorientation


【解决方案1】:

在您的 applicationDidFinishLaunching 方法中放入此代码

[[UIDevice currentDevice] setOrientation:UIDeviceOrientationLandscape];

这会将您的应用程序设置为横向模式,而与设备无关。

【讨论】:

    【解决方案2】:

    如果您的应用程序使用 UINavigationController,那么您应该将其子类化并在 IB 中设置类。然后,您需要覆盖以下方法以同时支持 iOS5 和 iOS6:

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
    {
      return interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
     interfaceOrientation == UIInterfaceOrientationLandscapeRight;
    }
    
    - (NSUInteger)supportedInterfaceOrientations;
    {
      return UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight;
    }
    
    - (BOOL) shouldAutorotate;
    {
      return YES;
    }
    

    【讨论】:

      【解决方案3】:

      在 ios 6 中它们是“shouldAutorotateToInterfaceOrientation”方法已弃用,所以你想在 ios 5 和 ios 6 中运行构建。

      然后,请进入构建阶段部分并打开编译源。

      然后,将该行粘贴到所有视图控制器中

      -fno-objc-arc

      然后粘贴代码

             - (BOOL)shouldAutorotateToInterfaceOrientation:
      (UIInterfaceOrientation)toInterfaceOrientation {
           return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
       interfaceOrientation == UIInterfaceOrientationLandscapeRight);
         }
      

      并确保摘要页面支持界面方向仅选择左右横向。

      【讨论】:

      • 为什么建议设置-fno-objc-arc?我认为它与自转无关。
      • 它在 ios 6 中运行已弃用的方法,你可以说旧的 ios 方法在已弃用的较新版本中运行。
      • 不,它会为特定文件禁用 ARC。您的意思是 -Wno-deprecated?
      【解决方案4】:

      只需在ViewController中添加以下方法

      - (BOOL)shouldAutorotateToInterfaceOrientation:
          (UIInterfaceOrientation)toInterfaceOrientation {
               return (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
           toInterfaceOrientation == UIInterfaceOrientationLandscapeRight);
      }
      

      shouldAutorotateToInterfaceOrientation 方法在 iOS 6 中已弃用,但仍需要 iOS 5 支持。

      【讨论】:

      • 其实可以,但是当我使用presentViewController功能时,应用又转了
      • ViewController 中添加相同的方法,由presentViewController 方法呈现。
      猜你喜欢
      • 1970-01-01
      • 2012-12-30
      • 2014-11-28
      • 2012-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-25
      相关资源
      最近更新 更多