iPhoneX适配(UI)

2018-01-26  本文已影响97人  An_Jun

1.相关宏

//判断设备是iPhoneX-------->>(X后设备都会适配)
#define kDevice_Is_iPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)  //height>=812
//屏幕宽适配(这里6对应的1,效果是以6为基准的)
#define wWidthAspect (KScreenWidth >= 414 ? 1.10 : (KScreenWidth >= 375 ? 1 : 0.85))
//屏幕高适配(这里6对应的1,效果是以6为基准的)
#define wHeightAspect (kScreenHeight >= 736 ? 1.10 : (kScreenHeight >= 667 ? 1 : 0.85))
//屏幕高适配(iPhoneX:(375 812))-------->>解决宽高相等的控件
#define wHeightAspectSpecial (kDevice_Is_iPhoneX ? 1 : wHeightAspect)
 //状态栏高度-------->>(适配iPhoneX)
#define kStatusBarHeight ([[UIApplication sharedApplication] statusBarFrame].size.height)
//iPhoneX状态栏差值(16)-------->>(适配iPhoneX)
#define kIPhoneXStatusBarDIFHeight (24-8) //状态栏-边距
//iPhoneX距上-------->>(适配iPhoneX)
#define OffSetForiPhoneX(x) (kDevice_Is_iPhoneX ? (x + kIPhoneXStatusBarDIFHeight) : x)
//导航栏高度
#define kNavigationBarHeight(44)
//状态栏+导航栏高度-------->>(适配iPhoneX)
#define kNavigationHeight (([[UIApplication sharedApplication] statusBarFrame].size.height) + (kNavigationBarHeight))

2.动态宽高的适配

iPhoneX之前:状态栏:20 导航栏:20+44
iPhoneX之后:状态栏:44 导航栏:44+44

a.判断设备是iPhoneX(这里应该判断高>=812,因为X之后设备估计都会有刘海)
([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.状态栏:kStatusBarHeight(获取系统),kIPhoneXStatusBarDIFHeight(X与之前手机状态栏的差值);
c.导航栏:kNavigationHeight(获取系统);
d.距上距离动态#define OffSetForiPhoneX(x) (kDevice_Is_iPhoneX?(x + kIPhoneXStatusBarDIFHeight): x);
e.高动态:#define wHeightAspectSpecial (kDevice_Is_iPhoneX?1 : wHeightAspect)
f.等宽 等高的控件,动态宽高用wWidthAspect,一半用(61*wWidthAspect)/2;

3.图片的适配

iPhoneX之前:方式一:UIViewContentModeScaleToFill方式二:wHeightAspect
iPhoneX之后:方式一:UIViewContentModeScaleAspectFit方式二:wHeightAspectSpecial

4.TouchID的适配

iPhoneX之后:去除了TouchID的功能,新增faceID。
现象:XHRValidateTouchIDNotEnrolled(设备未设置指纹)
解决:判断是X的话提示@“设备不支持指纹认证!”

5.其他适配(见链接)

https://www.jianshu.com/p/d40d701889a6
https://www.jianshu.com/p/670318acae90
https://www.jianshu.com/p/e43deb209bab
https://www.jianshu.com/p/1787fd64b73d
https://www.jianshu.com/p/4d2342d87827
https://www.jianshu.com/p/aff9509cfe29
https://www.jianshu.com/p/ea7507d06d60

上一篇下一篇

猜你喜欢

热点阅读