屏幕尺寸等于分辨率吗?如果你说是,那我在问,iPadAir 和 iPadmini3 分辨率一样吗?那尺寸呢?
OpenGL绘制地图要依据不同得ppi做适配,UIScreen 和UIDevice这两个类中并没有发现任何关于ppi接口的信息。 而计算公式又需要知道屏幕尺寸:
// float w = [UIScreen mainScreen].bounds.size.width; // float h = [UIScreen mainScreen].bounds.size.height; // dpi = sqrt( w*w + h*h ) / 屏幕尺寸 ;
记得当时在两个群里问如何获取屏幕尺寸的时候,被人一顿喷。ios开发连这个都不知道,甚是悲伤,咱只好掩面继续百度,google。
在iPhone 6 出来之前iPhone和iPod的ppi都是326。
iPad 的就比较特殊 iPadmini 是 163 *2 其他的是 132 * 2 乘2是代表是否为R屏;
如果能区分是不是mimi就能解决问题,现在的问题就是变成如何获取ios设备硬件信息。继续换关键字百度,google;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { dpi = 163 * scale; } else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { if (is iPad mimi) { dpi = 163 * scale; } else { dpi = 132 * scale; } } else { dpi = 163 * scale; }
最后找到一段代码通过获取设备的硬件信息,和官网上得型号做匹对:
- (NSString*) machine { struct utsname systemInfo; uname(&systemInfo); NSString* code = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding]; static NSDictionary* deviceNamesByCode = nil; if (!deviceNamesByCode) { deviceNamesByCode = @{@"i386" :@"Simulator", @"iPod1,1" :@"iPod Touch", @"iPod2,1" :@"iPod Touch", @"iPod3,1" :@"iPod Touch", @"iPod4,1" :@"iPod Touch", @"iPhone1,1" :@"iPhone", @"iPhone1,2" :@"iPhone", @"iPhone2,1" :@"iPhone", @"iPad1,1" :@"iPad", @"iPad2,1" :@"iPad 2", @"iPad3,1" :@"iPad", @"iPhone3,1" :@"iPhone 4", @"iPhone4,1" :@"iPhone 4S", @"iPhone5,1" :@"iPhone 5", @"iPhone5,2" :@"iPhone 5", @"iPad3,4" :@"iPad", @"iPad2,5" :@"iPad Mini", @"iPhone5,3" :@"iPhone 5c", @"iPhone5,4" :@"iPhone 5c", @"iPhone6,1" :@"iPhone 5s", @"iPhone6,2" :@"iPhone 5s", @"iPad4,1" :@"iPad Air", @"iPad4,2" :@"iPad Air", @"iPad2,5" :@"iPad Mini", @"iPad2,6" :@"iPad Mini" , @"iPad2,7" :@"iPad Mini", @"iPad4,4" :@"iPad Mini", @"iPad4,5" :@"iPad Mini" , @"iPad4,6" :@"iPad Mini", @"iPad4,7" :@"iPad Mini", @"iPad4,8" :@"iPad Mini", @"iPad4,9" :@"iPad Mini", @"iPhone7,1" :@"iPhone 6 Plus", // Phone 6 Plus @"iPhone7,2" :@"iPhone 6", // Phone 6 Plus }; } NSString* deviceName = [deviceNamesByCode objectForKey:code]; return deviceName; }