闲来无事,认真整理了一下iPhone机型,查看博客的时候有点疑惑为什么有的判断机型有两种尺寸呢?为了解决这个问题,用真机进行测试,发现在标准模式、放大模式下获取到的屏幕尺寸、分辨率都发生了变化。
在iPhone6之前只存在一个标准模式,在iPhone6之后推出了放大模式,用户可以进行切换。
iPhone6标准模式,[UIScreen mainScreen].bounds.size = (375, 667)(以下简称尺寸),[[UIScreen mainScreen] currentMode].size) = (750,1334)(以下简称分辨率)。
iPhone6放大模式,尺寸= (320, 568),分辨率 = (640, 1136)
iPhone6Plus标准模式,尺寸= (414, 736),分辨率 =(1242, 2208)
iPhone6Plus放大模式,尺寸= (375, 667),分辨率 = (1125, 2001)
iPhoneX标准模式(没有放大模式),尺寸 = (375, 812),分辨率 = (1125, 2436)
iPhone6之前没有放大模式,尺寸分辨率如下:
iPhone5标准模式,尺寸 = (320,568),分辨率 = (640,1136)
iPhone4标准模式,尺寸 = (320,480),分辨率 = (640,960)
所以只要适配了iPhone5,那么iPhone6的放大模式也就适配了,唯一需要特殊处理的是iPhone6Plus的放大模式和iPhoneX,所以我的判断代码如下:
1.OC版
#define IS_IPHONE4 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)
#define IS_IPHONE5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
#define IS_IPHONE6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? (CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size)) : NO)
#define IS_IPHONE6_PLUS_SCALE ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2001), [[UIScreen mainScreen] currentMode].size) : NO)
#define IS_IPHONE6_PLUS ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? (CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size)) : NO)
#define IS_IPHONE_X ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)
2、swift版
let IS_IPHONE4 = (UIScreen.instancesRespond(to: #selector(getter: UIScreen.main.currentMode)) ? CGSize(width: 640, height: 960).equalTo((UIScreen.main.currentMode?.size)!) : false)
let IS_IPHONE5 = (UIScreen.instancesRespond(to: #selector(getter: UIScreen.main.currentMode)) ? CGSize(width: 640, height: 1136).equalTo((UIScreen.main.currentMode?.size)!) : false)
let IS_IPHONE6 = (UIScreen.instancesRespond(to: #selector(getter: UIScreen.main.currentMode)) ? CGSize(width: 750, height: 1334).equalTo((UIScreen.main.currentMode?.size)!) : false)
let IS_IPHONE6_PLUS = (UIScreen.instancesRespond(to: #selector(getter: UIScreen.main.currentMode)) ? CGSize(width: 1242, height: 2208).equalTo((UIScreen.main.currentMode?.size)!) : false)
let IS_IPHONE6_PLUS_SCALE = (UIScreen.instancesRespond(to: #selector(getter: UIScreen.main.currentMode)) ? CGSize(width: 1125, height: 2001).equalTo((UIScreen.main.currentMode?.size)!) : false)
let IS_IPHONE_X = (UIScreen.instancesRespond(to: #selector(getter: UIScreen.main.currentMode)) ? CGSize(width: 1125, height: 2436).equalTo((UIScreen.main.currentMode?.size)!) : false)
我的理解就是这样,如有错误之处,还望指出,谢谢
参考地址如下:
IOS开发中常用一下方法