我目前正在为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故事板。
此代码仅适用于物理设备吗?我是否需要单独的模拟器代码?
并非如此简单。一些自定义界面必须需要与iPhone4不同的iphone 5的情节图板,添加或删除额外的面板以额外的尺寸添加额外的按钮或菜单。 – vgonisanz
并非如此简单,特别是增加了iPhone 6和6 Plus后,现在您必须提供5种尺寸的布局,而自动布局并不能真正将其切割得很好。 – alejandrormz