【发布时间】:2013-10-11 17:52:52
【问题描述】:
我想向我的 iOS6 用户和 iOS7 用户展示一个故事板。我该怎么做?
【问题讨论】:
标签: ios xcode storyboard ios7
我想向我的 iOS6 用户和 iOS7 用户展示一个故事板。我该怎么做?
【问题讨论】:
标签: ios xcode storyboard ios7
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
//load and show ios6 storyboard
}
else {
//load and show ios7 storyboard
}
【讨论】:
您可以使用此代码获取 iOS 版本:
[[UIDevice currentDevice] systemVersion]
例如,要检测 iOS 6,您可以执行以下操作:
if ([[UIDevice currentDevice].systemVersion hasPrefix:@"6"]) {
// ...
}
然后,要为 iOS 6 和 7 加载不同的故事板,您可以执行以下操作:
if ([[UIDevice currentDevice].systemVersion hasPrefix:@"6"]) {
myStoryboard = [UIStoryboard storyboardWithName:@"Storyboard_6" bundle:nil];
} else {
myStoryboard = [UIStoryboard storyboardWithName:@"Storyboard_7" bundle:nil];
}
编辑: 如其他答案所述,检测 iOS 版本的一种可以说是更好的方法是使用 NSFoundationVersionNumber,因为不需要对 systemVersion 进行字符串解析。
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
myStoryboard = [UIStoryboard storyboardWithName:@"Storyboard_6" bundle:nil];
} else {
myStoryboard = [UIStoryboard storyboardWithName:@"Storyboard_7" bundle:nil];
}
【讨论】:
您可以在 AppDelegate 中尝试这样的事情(非常重要)
UIStoryboard *storyboard = nil;
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
storyboard = [UIStoryboard storyboardWithName:@"iOS7_AND_ABOVE" bundle:[NSBundle mainBundle]];
} else {
storyboard = [UIStoryboard storyboardWithName:@"iOS_below_7" bundle:[NSBundle mainBundle]];
}
【讨论】: