如果两个故事板在3.5英寸屏幕上运行,而另一个用于4英寸屏幕,则将其放置在两个故事板的代码中。我有两个故事板。一个名为Main.storyboard,另一个名为Main2.storyboard。
答案 0 :(得分:1)
代码进入AppDelegate.m文件,看起来与此类似
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIStoryboard *mainstoryboard = [UIStoryboard storyboardWithName:@"AlternateStoryboard" bundle:nil];
UIViewController *vc = [mainstoryboard instantiateInitialViewController];
self.window.rootViewController = vc;
return YES;
}
您首先需要检查屏幕尺寸,当然,请参阅UIScreen的文档。
答案 1 :(得分:0)
这样的事可能会有所帮助。在AppDelegate的application:didFinishLaunchingWithOptions:
方法中:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone
&& [UIScreen mainScreen].bounds.size.height == 568.0) {
//is 4 inch screen
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *viewController = [storyboard instantiateInitialViewController];
self.window.rootViewController = viewController;
}
else {
//is 3.5 inch screen
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main2" bundle:nil];
UIViewController *viewController = [storyboard instantiateInitialViewController];
self.window.rootViewController = viewController;
}
return YES;
}
if/else
语句检查屏幕大小并加载相应的故事板。