当我们拥有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 ");
}
现在又多了2部iPhone,问题是,做对吗?5 storyboards
适用于所有 iPhone 和 iPad ?在我看来,这是一件错误的事情,但我找不到一种方法来排列一个设备中的视图,并使其适合所有其他设备 - 并且确保它always效果很好。
现在正确的做法是什么?
最好的方法是使用自动布局,但如果由于某种原因您仍然必须针对不同的屏幕尺寸使用不同的故事板,以下是有效的代码。
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 plus 屏幕分辨率,请添加启动图像
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)