【问题标题】:how to make app compatible for ios6 when using xcode5使用 xcode 5 时如何使应用程序与 ios 6 兼容
【发布时间】:2023-03-06 07:18:02
【问题描述】:

我花了一整天的时间来尝试我的make可以兼容ios7和ios6,但是很累。当我在ios 7中运行并将基础sdk设置为ios7时,我的应用程序运行良好之后。我也将部署目标设置为 7.0。

现在,当我将基本 sdk 设置为 ios6 并将部署目标设置为 6.1 时,我的应用程序仍在运行,但问题是其 GUI 失真。在模拟器 6.1 中尝试过,也遇到了这个问题。

导航栏隐藏,所有图像标签文本字段表格视图也设置为底部,就像它们在 ios7 中的固定位置一样。我不想放 4 xib 我已经放了 2 xib 一个用于 3.5 英寸显示器和 4 英寸显示器。

【问题讨论】:

  • 你为什么不使用自动布局它会解决你的大部分问题,你还需要检查运行的是哪个 iOS 以便你可以调整你的视图,寻找升级指南
  • @Retro 但如果我使用自动布局。并将导航栏设置为 3.5 英寸,它也会影响到 4 英寸显示屏,我该怎么办?
  • 使用自动布局通过raywenderlich.com/50317/…你不需要2或4个xib你可以使用单个xib。
  • 将您的任何 UIView 固定到顶部或底部,它将根据 3.5 或 4 英寸设备自动调整视图。
  • @RahulV.Mane 我已经制作了 2 个 xib,它变成了硬编码有什么办法吗?

标签: ios objective-c ios6 ios7 xcode5


【解决方案1】:

在 info.plist 中添加一个标志(基于视图控制器...plist 中的最后一个)将其设置为 NO

【讨论】:

  • if ([self respondsToSelector:@selector(edgesForExtendedLayout)]) self.edgesForExtendedLayout = UIRectEdgeNone;
【解决方案2】:

如果我必须根据不同的 iOS 版本进行更改,我会使用以下类来定义可以检测我正在使用的版本的函数。它也只需要一个头(.h)文件,不需要实现(.m)文件。

我称这个类为 VersionMacros。

版本宏.h:

/*
 *  System Versioning Preprocessor Macros
 *  Incluse this header if you want to adjust something based on a system version
 */

#define SYSTEM_VERSION_EQUAL_TO(v)                  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)

//Use these functions to detect versions. Also import this header file into the file u want to use these funcs.

然后,当您想为两个版本使用不同的 xib 时,您可以调用它。

      if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO("7.0"))
      {
          //The version of the device is iOS7.0 or higher.

          //call controller with ios7 xib here
      }
      else
      {
          //The version of the device is lower then iOS7.0.

          //call controller with ios6 xib here
      }

您也可以只调整需要调整的元素的框架,而不是制作和调用不同的 xib。 (这是我喜欢的) 这看起来像这样。

float versionMarginY = 0.0;

if(SYSTEM_VERSION_EQUAL_TO("7.0"))
{
    //if system version is exactly 7.0
    versionMarginY = 64.0;
}
else if(SYSTEM_VERSION_EQUAL_TO("6.0"))
{
    //if system version is exactly 6.0
    versionMarginY = 44.0;
}
else
{
    //for all other versions we do this
}

//Then adjust a certain view that you can reach in this method
someView.frame = CGRectMake(0, 0 + versionMarginY, someWidthThatHasSomeKindOfValue, someHeightThatHasSomeKindOfValue);

希望这会有所帮助!

【讨论】:

  • 有一个错误,我必须输入 V 我已经尝试过但它得到了错误。
  • SomeView 中会有什么内容?
  • 您应该将 iOS 版本号作为字符串而不是 v。就像示例中的“6.0”或“7.0”一样。 SomeView 将是您可以管理的 xib 中的元素。就像你放在 xib 上并与视图控制器连接的一些 UIView 一样
  • 你的意思是我必须为每个班级设置iboutlet并设置uiview?
  • 是的,完全正确。您可以设置 IBOutlet 以获取需要调整的视图(或视图)的句柄。
【解决方案3】:

我使用此条件通过代码在 iOS 6 和 7 上解决图形问题

if(floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1){
        //make it look nice iOS7
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-23
    • 2014-11-04
    • 2012-02-12
    • 2014-07-23
    • 1970-01-01
    • 2013-10-29
    相关资源
    最近更新 更多