2014-11-23 128 views
0

我有两个故事板的应用程序,一个用于4英寸的屏幕和一个用于3.5英寸的屏幕。我在我的“didfinishlaunchingwithoptions”下面的代码加载在推出合适的故事板...Xcode在发布时选择故事板(Xcode 6)

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英寸的故事板,无论使用哪种设备,你知道如何在Xcode 6中使用iOS 8吗?

+0

也许你可以在这里找到自己的解决方案:http://stackoverflow.com/questions/27086305/using-multiple-storyboards-in-xcode(注意plist的东西) – Yaser 2014-11-23 07:40:58

+0

一个更好的问题可能是“我如何在3.5英寸和4英寸的屏幕上制作相同的故事板“,因为你现在也有iPhone 6和6 plus担心,你的解决方案正在迅速变得不可持续。 – jrturton 2014-11-23 08:10:48

+0

这适用于6和6加上不正确的4,并@yaser给我的链接是好的,但我无法弄清楚。 – msweet168 2014-11-23 08:12:02

回答

0

可以具备这些条件,一个为iPhone 4,4s(960),另一个用于5,5s,6,6plus(1136)最后的登记,

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]; 
    }