使用xcode5时如何使应用程序与ios6兼容

使用xcode5时如何使应用程序与ios6兼容,ios,objective-c,ios6,ios7,xcode5,Ios,Objective C,Ios6,Ios7,Xcode5,我花了一整天的时间来尝试我的make是否能兼容ios7和ios6,但很累。当我在ios 7中运行并将基本sdk设置为ios7及更高版本时,我的应用程序运行得非常好。我还将部署目标设置为7.0 现在,当我将基本sdk设置为ios6并将部署目标设置为6.1时,我的应用程序仍在运行,但问题是它的GUI被扭曲了。在模拟器6.1中尝试过,也遇到了这个问题 导航栏隐藏,所有图像标签textfield tableview也设置为底部,就像ios7中的固定位置一样。我不想放置4个xib,我已经为3.5英寸显示器

我花了一整天的时间来尝试我的make是否能兼容ios7和ios6,但很累。当我在ios 7中运行并将基本sdk设置为ios7及更高版本时,我的应用程序运行得非常好。我还将部署目标设置为7.0

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


导航栏隐藏,所有图像标签textfield tableview也设置为底部,就像ios7中的固定位置一样。我不想放置4个xib,我已经为3.5英寸显示器和4英寸显示器放置了2个xib。

在info.plist中添加一个标志(基于视图控制器…plist中的最后一个)如果我必须根据不同的iOS版本进行更改,请将其设置为NO

,我将使用以下类定义可以检测我使用的版本的函数。它还只需要一个头文件(.h)而不需要实现文件(.m)

我称这个类为VersionMacros

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);

希望这有帮助

我使用此条件通过使用iOS 6和iOS 7的代码修复图形问题

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

你为什么不使用自动布局呢?它会解决你的大部分问题,你还需要检查哪个iOS正在运行,这样你就可以调整你的视图,寻找旅游指南upgrade@Retro但是,如果我使用auto layout.并将导航栏设置为3.5英寸,它也会影响到4英寸的显示,那么我该怎么做呢?使用autolayout检查您不需要2或4个xib,您可以使用单个xib。将任何UIView固定到顶部或底部,它将根据3.5或4英寸设备自动调整视图。@RahulV.Mane i已经做了2个xib,它变成了硬编码有什么办法吗?如果([self respondsToSelector:@selector(edgesForExtendedLayout)])self.edgesForExtendedLayout=UIRectEdgeNone;有一个错误,我必须用它来代替V,我已经尝试过了,但是它出现了错误。SomeView中会出现什么?你应该把iOS版本号作为字符串来代替V。如示例中的“6.0”或“7.0”。SomeView将是您可以管理的xib中的元素。就像你放在xib上并与ViewControllery连接的UIView一样,你的意思是我必须为每个类设置iboutlet并设置UIView?是的,没错。您可以设置IBOutlet以获得需要调整的视图的句柄。