2013-01-02 26 views
2

我目前正在为iPhone 3GS开发一款应用程序。部署目标设置为5.1,我创建了一个包含大量赛段和场景的丰富故事板。昨晚我的想法是,我想让iPad,iPhone 4和iPhone 5的应用程序可用。我决定为不同的屏幕尺寸/分辨率创建一个单独的故事板。现在我不确定这是否是最佳做法,因为我最近刚刚开始阅读关于SO的弹簧和支柱,所以我不知道关于它的很多信息,但为了我的缘故,我只是想推出一个不同的故事板当应用程序完成启动时。然而,这种期望的效果没有发生。如何开发多个iOS设备,即多个故事板?

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    // Override point for customization after application launch. 
    // ViewControllerWelcome *viewControllerWelcome = (ViewControllerWelcome *)[[ViewControllerWelcome alloc]init]; 

// NSManagedObjectContext *context = (NSManagedObjectContext *) [self managedObjectContext]; 
// if (!context) { 
//  NSLog(@"\nCould not create *context for self"); 
// } 

    //[viewControllerWelcome setManagedObjectContext:context]; 

    // Do I need to declare my view controllers here? 

    // Pass the managed object context to the view controller. 

    CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size; 

    if (iOSDeviceScreenSize.height == 480) 
    { 
     // Instantiate a new storyboard object using the storyboard file named iPhoneLegacy 
     UIStoryboard *iPhoneLegacy = [UIStoryboard storyboardWithName:@"iPhoneLegacy" bundle:nil]; 

     // Instantiate the initial view controller object from the storyboard 
     UIViewController *ViewControllerWelcome = [iPhoneLegacy 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 = ViewControllerWelcome; 

     // set the window object to be the key window and show it 
     [self.window makeKeyAndVisible]; 
    } 

    if (iOSDeviceScreenSize.height == 968) 
    { 
     // Instantiate a new storyboard object using the storyboard file named iPhone4 
     UIStoryboard *iPhone4 = [UIStoryboard storyboardWithName:@"iPhone4" bundle:nil]; 

     UIViewController *ViewControllerWelcome = [iPhone4 instantiateInitialViewController]; 
     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
     self.window.rootViewController = ViewControllerWelcome; 
     [self.window makeKeyAndVisible]; 
    } 

    // iPhone 5 1136 x 640 

    // iPad Legacy 1024 x 768 

    return YES; 
} 

当我尝试测试,看看不同的故事板文件加载在模拟器,模拟器只是用来加载iPhoneLegacy故事板。

此代码仅适用于物理设备吗?我是否需要单独的模拟器代码?

回答

4

所有的拳头,删除您的额外故事板!你只需要一个用于iPhone,另一个用于iPad。

有一种简单的方法可以为所有iPhone/iPod Touch尺寸制作单个故事板。

  1. 仅保留一个iPhone屏幕大小的故事板(包括iPhone 5)。
  2. 为所有图像制作@ 2x文件。
  3. 要在3.5英寸和4英寸之间切换,苹果在右下角提供了一个按钮,看起来像一个带箭头的矩形,该按钮将在3.5英寸和4英寸之间切换。

这就是它!为每个iPhone/iPod Touch制作单个故事板实际上不需要任何代码。


对于iPad上,你将需要创建一个为iPad做了一个新的故事板,你将需要更新您的UI代码,以确保它与iPhone和iPad的屏幕尺寸兼容。同样,请确保为iPad制作@ 2x图片大小。

+1

并非如此简单。一些自定义界面必须需要与iPhone4不同的iphone 5的情节图板,添加或删除额外的面板以额外的尺寸添加额外的按钮或菜单。 – vgonisanz

+0

并非如此简单,特别是增加了iPhone 6和6 Plus后,现在您必须提供5种尺寸的布局,而自动布局并不能真正将其切割得很好。 – alejandrormz