1. 屏幕大小问题点
随着iOS的碎片化,特别是 4/4s/5/5s/6/6p出来后,每个屏幕的高度宽度都不一样,如果背景图片不具有拉伸平铺的性质,
则同时@2x图的4/4s/5/5s/6 的图片将被压缩或拉伸。
关于iOSLauchImage画面适应iPhone5 iPhone5s iPhone6 iPhone6P分辨率的介绍有很多,比如将LaunchImage设置成
多个分辨率,具体请参照。
2.背景图的设置方法。
一般采用屏幕大小去判断是哪种苹果机型如一下代码:
#import "BXDevice.h"
@implementation BXDevice
+(thisDeviceClass) currentDeviceClass {
CGFloat greaterPixelDimension = (CGFloat) fmaxf(((float)[[UIScreen mainScreen]bounds].size.height),
((float)[[UIScreen mainScreen]bounds].size.width));
switch ((NSInteger)greaterPixelDimension) {
case 480:
return (( [[UIScreen mainScreen]scale] > 1.0) ? thisDeviceClass_iPhoneRetina : thisDeviceClass_iPhone );
break;
case 568:
return thisDeviceClass_iPhone5;
break;
case 667:
return thisDeviceClass_iPhone6;
break;
case 736:
return thisDeviceClass_iPhone6plus;
break;
case 1024:
return (( [[UIScreen mainScreen]scale] > 1.0) ? thisDeviceClass_iPadRetina : thisDeviceClass_iPad );
break;
default:
return thisDeviceClass_unknown;
break;
}
}
+ (NSString *)magicSuffixForDevice
{
switch ([BXDevice currentDeviceClass]) {
case thisDeviceClass_iPhone:
return @"";
break;
case thisDeviceClass_iPhoneRetina:
return @"@2x";
break;
case thisDeviceClass_iPhone5:
return @"-568h@2x";
break;
case thisDeviceClass_iPhone6:
return @"-667h@2x"; //or some other arbitrary string..
break;
case thisDeviceClass_iPhone6plus:
return @"-736h@3x";
break;
case thisDeviceClass_unknown:
default:
return @"";
break;
}
}
+(UIImage *)imageDeviceWithName:(NSString *)fileName
{
UIImage *result = nil;
NSString *nameWithSuffix = [fileName stringByAppendingString:[BXDevice magicSuffixForDevice]];
result = [UIImage imageNamed:nameWithSuffix];
if (!result) {
result = [UIImage imageNamed:fileName];
}
return result;
}
@end
struct utsname systemInfo;
uname(&systemInfo);
NSString *platform = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
这个platform的值比较杂乱,其中iphone6 得到的是”iPhone7,2“ 而iphone6P得到的是“iphone7,1”