1.相關(guān)宏
//判斷設(shè)備是iPhoneX-------->>(X后設(shè)備都會(huì)適配)
#define kDevice_Is_iPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO) //height>=812
//屏幕寬適配(這里6對(duì)應(yīng)的1嗦枢,效果是以6為基準(zhǔn)的)
#define wWidthAspect (KScreenWidth >= 414 ? 1.10 : (KScreenWidth >= 375 ? 1 : 0.85))
//屏幕高適配(這里6對(duì)應(yīng)的1,效果是以6為基準(zhǔn)的)
#define wHeightAspect (kScreenHeight >= 736 ? 1.10 : (kScreenHeight >= 667 ? 1 : 0.85))
//屏幕高適配(iPhoneX:(375 812))-------->>解決寬高相等的控件
#define wHeightAspectSpecial (kDevice_Is_iPhoneX ? 1 : wHeightAspect)
//狀態(tài)欄高度-------->>(適配iPhoneX)
#define kStatusBarHeight ([[UIApplication sharedApplication] statusBarFrame].size.height)
//iPhoneX狀態(tài)欄差值(16)-------->>(適配iPhoneX)
#define kIPhoneXStatusBarDIFHeight (24-8) //狀態(tài)欄-邊距
//iPhoneX距上-------->>(適配iPhoneX)
#define OffSetForiPhoneX(x) (kDevice_Is_iPhoneX ? (x + kIPhoneXStatusBarDIFHeight) : x)
//導(dǎo)航欄高度
#define kNavigationBarHeight(44)
//狀態(tài)欄+導(dǎo)航欄高度-------->>(適配iPhoneX)
#define kNavigationHeight (([[UIApplication sharedApplication] statusBarFrame].size.height) + (kNavigationBarHeight))
2.動(dòng)態(tài)寬高的適配
iPhoneX之前:狀態(tài)欄:20 導(dǎo)航欄:20+44
iPhoneX之后:狀態(tài)欄:44 導(dǎo)航欄:44+44
a.判斷設(shè)備是iPhoneX(這里應(yīng)該判斷高>=812,因?yàn)閄之后設(shè)備估計(jì)都會(huì)有劉海)
([UIScreen instancesRespondToSelector:@selector(currentMode)]?([[UIScreen mainScreen]currentMode].size.height)>= 812 : NO) //height>812(#define kDevice_Is_iPhoneX([UIScreen instancesRespondToSelector:@selector(currentMode)]?CGSizeEqualToSize(CGSizeMake(1125,2436),[[UIScreen mainScreen]currentMode].size): NO) //CGRectGetHeight>=812)
b.狀態(tài)欄:kStatusBarHeight(獲取系統(tǒng)),kIPhoneXStatusBarDIFHeight(X與之前手機(jī)狀態(tài)欄的差值)甥绿;
c.導(dǎo)航欄:kNavigationHeight(獲取系統(tǒng))苍在;
d.距上距離動(dòng)態(tài)#define OffSetForiPhoneX(x) (kDevice_Is_iPhoneX?(x + kIPhoneXStatusBarDIFHeight): x)掂骏;
e.高動(dòng)態(tài):#define wHeightAspectSpecial (kDevice_Is_iPhoneX?1 : wHeightAspect)
f.等寬 等高的控件焕毫,動(dòng)態(tài)寬高用wWidthAspect拉岁,一半用(61*wWidthAspect)/2;
3.圖片的適配
iPhoneX之前:方式一:UIViewContentModeScaleToFill方式二:wHeightAspect
iPhoneX之后:方式一:UIViewContentModeScaleAspectFit方式二:wHeightAspectSpecial
4.TouchID的適配
iPhoneX之后:去除了TouchID的功能惠桃,新增faceID浦夷。
現(xiàn)象:XHRValidateTouchIDNotEnrolled(設(shè)備未設(shè)置指紋)
解決:判斷是X的話提示@“設(shè)備不支持指紋認(rèn)證!”
5.其他適配(見鏈接)
http://www.reibang.com/p/d40d701889a6
http://www.reibang.com/p/670318acae90
http://www.reibang.com/p/e43deb209bab
http://www.reibang.com/p/1787fd64b73d
http://www.reibang.com/p/4d2342d87827
http://www.reibang.com/p/aff9509cfe29
http://www.reibang.com/p/ea7507d06d60