iPhone 6的另一个故事板?
当我们有iPhone 4 and 5
,我们检查了屏幕尺寸,并为每个iPhone制作了2个故事板。
//iPhone 4 if (height == 480) { storyboard = [UIStoryboard storyboardWithName:@"StoryboardiPhone" bundle:nil]; NSLog(@"Device has a 3.5inch Display."); } //iPhone 5 else if (height == 568) { storyboard = [UIStoryboard storyboardWithName:@"StoryboardiPhone5" bundle:nil]; NSLog(@"Device has a 4inch Display."); } //iPads else { storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil]; NSLog(@"Device has a iPad Display "); }
现在又有两个iPhone,问题是,为所有的iPhone和iPad制作5个 storyboards
是否正确? 在我看来,这是一个错误的做法,但是我找不到一种方法来将这些视图安排在一个设备上,并使其适合所有其他设备,并且确保它始终能够很好地工作。
现在什么是正确的方法?
不,你应该使用AutoLayout,并写出适当的约束,让系统调整您的用户界面的各种尺寸。
最好的办法是使用AutoLayout,但如果由于某种原因仍然需要为不同的屏幕尺寸使用不同的故事板,那么下面是一个工作代码。
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) { //iPad storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPad" bundle:nil]; }else{ if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone){ // The iOS device = iPhone or iPod Touch CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size; if (iOSDeviceScreenSize.height == 480){ // iPhone 3/4x storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone3_4X" bundle:nil]; }else if (iOSDeviceScreenSize.height == 568){ // iPhone 5 - 5s - 4 inch storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone5_5S" bundle:nil]; }else if (iOSDeviceScreenSize.height == 667){ // iPhone 6 4.7 inch storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone6" bundle:nil]; } else if (iOSDeviceScreenSize.height == 736){ // iPhone 6 Plus 5.5 inch storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone6Plus" bundle:nil]; } } }
要启用本机iPhone 6和iPhone 6以及屏幕分辨率,请添加启动图像
您应该在Interface Builder中为wAny / hAny“size class”deviseUI。 应用自动布局约束来描述视图如何适应不同的大小类。 如果您需要,您可以覆盖特定大小类别的某些约束。
您之前select基于设备加载故事板的代码应该被删除。 如果您使用尺寸类别,则不再需要。
有一个很好的WWDCvideo,介绍了自适应的用户界面和大小类。 我会build议看看。
- 如何让iAdBannerView跨越Adaptive Layout Storyboard xcode 6的全部宽度
- 在Storyboard中创build的ScrollView,使用0,0,0,0帧进行初始化
- 你如何在故事板中的UISearchbar的结果,并在另一个angular度使用这些结果?
- 故事板自动复制到新项目
- 在xcode 4.2的scrollview里面devise故事板
- AutoLayout的问题与在NIB文件中定义并在StoryBoard中使用的自定义视图
- 用编程方式使用Storyboards开发iOS的速度?
- 在具有.xib文件的项目中使用故事板 – iPhone
- 如何使用故事板呈现飞溅/login视图控制器