2

我想向我的 iOS6 用户和 iOS7 用户展示一个故事板。我怎样才能做到这一点?

4

3 回答 3

5
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
    //load and show ios6 storyboard
}
else {
    //load and show ios7 storyboard
}
于 2013-10-04T16:31:59.933 回答
3

您可以使用以下代码获取 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];
}
于 2013-10-04T16:29:39.893 回答
0

您可以在 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]];
 }
于 2013-10-04T16:32:06.120 回答