我的应用中有两个故事板,硬盘为3.5英寸设备,另一个为4英寸设备。我在我的app委托中有这个来检查屏幕的尺寸。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
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 == 480){
storyBoard = [UIStoryboard storyboardWithName:@"iphone4.storyboard" bundle:nil];
UIViewController *initViewController = [storyBoard instantiateInitialViewController];
[self.window setRootViewController:initViewController];
}
}
return YES;
}
但由于某些原因,这并没有起作用,所以我决定环顾四周,在一个新的方法中单独使用它,这是,
-(void)initializeStoryBoardBasedOnScreenSize {
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone)
{
CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;
if (iOSDeviceScreenSize.height == 480)
{
UIStoryboard *iPhone35Storyboard = [UIStoryboard storyboardWithName:@"iphone4.storyboard" bundle:nil];
UIViewController *initialViewController = [iPhone35Storyboard instantiateInitialViewController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = initialViewController;
[self.window makeKeyAndVisible];
}
if (iOSDeviceScreenSize.height == 568)
{
UIStoryboard *iPhone4Storyboard = [UIStoryboard storyboardWithName:@"Main.storyboard" bundle:nil];
UIViewController *initialViewController = [iPhone4Storyboard instantiateInitialViewController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = initialViewController;
[self.window makeKeyAndVisible];
}
} else if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)
{
UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
splitViewController.delegate = (id)navigationController.topViewController;
}
}
我不确定是什么导致它不显示,它只显示4英寸版本,即使我在iphone 4s模拟器中运行它。我忽略了一些超级简单的东西吗?