0

我需要在 Xcode 5 中为我的 iOS 7 应用程序创建 2 个故事板。我需要一个用于 4 英寸屏幕的故事板和一个用于 3.5 英寸屏幕的故事板,因为自动布局不适用于此应用程序。我有一个标题为“iPhone_3.5”和一个标题为“Main”。我将以下代码放在我的 AppDelegate.m 中:

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:@"iPhone_3.5.storyboard" bundle:nil];
        UIViewController *initViewController = [storyBoard instantiateInitialViewController];
        [self.window setRootViewController:initViewController];

    }

}

但是当我在 iPhone 4 上启动该应用程序时,它仍然显示 iPhone 5 故事板,因此看起来很糟糕。有什么我在这里想念的吗?谢谢!

4

1 回答 1

2

I am switching storyboards using storyBoardWithName:bundle same as yours but I didn't include the extension '.storyboard' to the string argument. Maybe you could try that up. Xcode may have trouble finding the storyboard file as a result it loads the default one which the Main.storyboard. Another thing is your equalities. Maybe you could use this instead.

if([UIScreen mainScreen].bounds.size.height>=568) {
       // load iPhone 4 inch storyboard.
} else {
     // load iPhone 3.5 inch storyboard
}
于 2013-10-29T07:20:16.493 回答