有不同的屏幕尺寸单独故事板?

基本上我有一个应用程序完成。 我唯一的问题在于,应用程序的devise只考虑了4英寸显示器。 当在3.5模拟器上运行.5英寸的应用程序丢失(显然)。

那么我的问题是,我怎样才能在Xcode 5中为不同的屏幕大小设置不同的故事板?

我知道,在我可以使用下面的一段代码之前:

-(void)initializeStoryBoardBasedOnScreenSize { if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone) { // The iOS device = iPhone or iPod Touch CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size; if (iOSDeviceScreenSize.height == 480) { // iPhone 3GS, 4, and 4S and iPod Touch 3rd and 4th generation: 3.5 inch screen (diagonally measured) // Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone35 UIStoryboard *Main_iPhone2 = [UIStoryboard storyboardWithName:@"Main_iPhone3" bundle:nil]; // Instantiate the initial view controller object from the storyboard UIViewController *initialViewController = [Main_iPhone2 instantiateInitialViewController]; // Instantiate a UIWindow object and initialize it with the screen size of the iOS device self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Set the initial view controller to be the root view controller of the window object self.window.rootViewController = initialViewController; // Set the window object to be the key window and show it [self.window makeKeyAndVisible]; } if (iOSDeviceScreenSize.height == 568) { // iPhone 5 and iPod Touch 5th generation: 4 inch screen (diagonally measured) // Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone4 UIStoryboard *Main_iPhone = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil]; // Instantiate the initial view controller object from the storyboard UIViewController *initialViewController = [Main_iPhone instantiateInitialViewController]; // Instantiate a UIWindow object and initialize it with the screen size of the iOS device self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Set the initial view controller to be the root view controller of the window object self.window.rootViewController = initialViewController; // Set the window object to be the key window and show it [self.window makeKeyAndVisible]; } } else if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) { // The iOS device = iPad UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController; UINavigationController *navigationController = [splitViewController.viewControllers lastObject]; splitViewController.delegate = (id)navigationController.topViewController; } } 

但是,与Xcode 5的交易,以及我相信这个代码不工作的原因是,在您的项目中有一个一般的部分,在整个特定设备types中build立一个故事板作为主要部分。

所以,要么完成不同的故事情节,要么有不同的方法,要么我在代码中做错了什么。 下面的代码显然被放在AppDelegate.m文件下面…所以不要以为我有什么错误。

谢谢,真正的帮助将不胜感激。 我真的想提交这个程序!

问候,帕特里西奥

在我的- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions方法在我的应用程序委托中,我有这个块:

 // Override point for customization after application launch. 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 != 1136){ storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard35" bundle:nil]; UIViewController *initViewController = [storyBoard instantiateInitialViewController]; [self.window setRootViewController:initViewController]; } } 

这覆盖了我的默认MainStoryboard,4英寸的屏幕,并加载我的3.5英寸的屏幕故事板。 在我的项目中,我仍然将MainStoryboard(4英寸屏幕版本)定义为主界面。

这在Xcode 5中工作。它在一个航运应用程序,所以它应该工作得很好。