使用2个故事板用于不同的屏幕尺寸Xcode 5 iOS 7 [英] Using 2 Storyboards for different screen sizes Xcode 5 iOS 7
问题描述
我需要在Xcode 5中为我的iOS 7应用程序创建2个故事板。我需要一个用于4英寸屏幕的故事板和一个用于3.5英寸的故事板,因为自动布局不适用于此应用程序。我有一个标题为iPhone_3.5和一个标题为主要。我在AppDelegate.m中放入以下代码:
I need to create 2 storyboards for my iOS 7 app in Xcode 5. I need a story board for the 4 inch screen and one for the 3.5 inch, because auto layout does not work with this app. I have one titled "iPhone_3.5" and one titled "Main". I put the following code in my 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故事板,因此看起来很糟糕。这里有什么我想念的吗?谢谢!
But when I launch the app on my iPhone 4, it still shows the iPhone 5 storyboard, and thus looks terrible. Is there something that I'm missing here? Thanks!
推荐答案
我正在使用storyBoardWithName切换故事板:与你的相同的捆绑包但我没有包含扩展名'.storyboard'到字符串参数。也许你可以尝试一下。 Xcode可能无法找到storyboard文件,因此它加载了Main.storyboard的默认文件。另一件事是你的平等。也许你可以改用它。
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
}
这篇关于使用2个故事板用于不同的屏幕尺寸Xcode 5 iOS 7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!