我有一个带两个故事板的应用程序,一个用于4英寸屏幕,一个用于3.5英寸屏幕。我在“didfinishlaunchingwithoptions”中有以下代码,以便在发布时加载正确的故事板......
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
UIStoryboard *storyBoard;
CGSize result = [[UIScreen mainScreen] bounds].size;
CGFloat scale = [UIScreen mainScreen].scale;
result = CGSizeMake(result.width * scale, result.height * scale);
if(result.height == 960){
storyBoard = [UIStoryboard storyboardWithName:@"3inchstoryboard" bundle:nil];
UIViewController *initViewController = [storyBoard instantiateInitialViewController];
[self.window setRootViewController:initViewController];
}
}
随着Xcode 6和iOS 8的发布,它不再有效,它只是为每次4英寸的故事板加载,无论什么设备,你知道如何让它在iOS 8上运行吗?在Xcode 6?
答案 0 :(得分:0)
你可以有这些条件,一个用于iPhone 4,4s(960),另一个用于5,5s,6,6plus(1136)最后用于ipads
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
UIStoryboard *storyBoard;
CGSize result = [[UIScreen mainScreen] bounds].size;
CGFloat scale = [UIScreen mainScreen].scale;
result = CGSizeMake(result.width * scale, result.height * scale);
if(result.height == 960){ //storyboard for 4,4s
storyBoard = [UIStoryboard storyboardWithName:@"storyboard4" bundle:nil];
UIViewController *initViewController = [storyBoard instantiateInitialViewController];
[self.window setRootViewController:initViewController];
}
if(result.height == 1136){ //storyboard for 5,5s,6,6plus
storyBoard = [UIStoryboard storyboardWithName:@"storyboard5" bundle:nil];
UIViewController *initViewController = [storyBoard instantiateInitialViewController];
[self.window setRootViewController:initViewController];
}
}else { //storyboard for ipads
storyBoard = [UIStoryboard storyboardWithName:@"storyboardipad" bundle:nil];
UIViewController *initViewController = [storyBoard instantiateInitialViewController];
[self.window setRootViewController:initViewController];
}