對於我來說,如果我不得不做出這樣的基於我用下面的不同IOS版本的變化類來定義可以檢測我正在使用哪個版本的函數。它也只需要一個頭文件(.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.
然後,當你想使用一個不同的廈門國際銀行兩個版本你可以調用它。
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系統運行以便您可以調整您的視圖,尋找升級指南 – Retro
@Retro,但如果我使用自動layout.and設置3.5英寸導航欄它也會影響到4英寸顯示器,所以我怎麼能? –
使用自動佈局通過http://www.raywenderlich.com/50317/beginning-auto-layout-tutorial-in-ios-7-part-1 您不需要2或4個xib,您可以使用單個xib來完成。 –