简体   繁体   中英

how to make app compatible for ios6 when using xcode5

这对于ios 7看起来很完美这是iOS 6 I spend a whole day to try that my make will be compatible for both ios7 and ios6,but tired.My app is running perfectly when I run in ios 7 and set the base sdk as ios7 and later. Also I put deployment target as 7.0.

Now when I set base sdk as ios6 and set deployment target as 6.1 then my app is still run but the problem is its GUI is distorted. Tried in simulator 6.1 and also getting this problem.

Navigation bar hides and all the images label textfield tableview are also set to bottom as they were as in fix position in ios7. I don't want to put 4 xib I already put 2 xib one for 3.5 inch display and for 4 inch display.

For me if I have to make changes that are based on different iOS version I use the following class to define functions that can detect which version I'm using. It also only needs a header (.h) file and no implementation (.m) file.

I call this class 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.

Then when you want to use a different xib for both versions you can just call this.

      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
      }

Instead of making and calling different xibs you can also just adjust the frames of the elements that need adjusting. (this is what I prefer) This would look something like this.

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

Hope this helps!

I used this condition to fix graphical issues by code working with iOS 6 and 7

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM