iPhoneX、iPhoneXS、iPhoneXR、iPhoneXSMax屏幕适配

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/st646889325/article/details/82992599

苹果所有设备屏幕尺寸

iPhoneXS和去年的iPhoneX

iPhoneXR和iPhoneXSMax

通过上面两张图片可以看出来,他们的安全域都一样,StatusBar的高都是44pt,底部都有Home虚拟按键区34pt,所以做适配的时候只需要判断是iPhoneX或者是iPhoneXS或者是iPhoneXR或者是iPhoneXSMax就行。

//获得屏幕的宽高

#define kScreenWidth ([UIScreen mainScreen].bounds.size.width)

#define kScreenHeight ([UIScreen mainScreen].bounds.size.height)

//iPhoneX / iPhoneXS

#define isIphoneX_XS (kScreenWidth == 375.f && kScreenHeight == 812.f ? YES : NO)

//iPhoneXR / iPhoneXSMax

#define isIphoneXR_XSMax (kScreenWidth == 414.f && kScreenHeight == 896.f ? YES : NO)

//异性全面屏

#define isFullScreen (isIphoneX_XS || isIphoneXR_XSMax)

// Status bar height.

#define StatusBarHeight (isFullScreen ? 44.f : 20.f)

// Navigation bar height.

#define NavigationBarHeight 44.f

// Tabbar height.

#define TabbarHeight (isFullScreen ? (49.f+34.f) : 49.f)

// Tabbar safe bottom margin.

#define TabbarSafeBottomMargin (isFullScreen ? 34.f : 0.f)

// Status bar & navigation bar height.

#define StatusBarAndNavigationBarHeight (isFullScreen ? 88.f : 64.f) 

判断是不是异性全面屏幕
#define isFullScreen (isIphoneX_XS || isIphoneXR_XSMax)
是在适配iPhoneX的基础上加的判断,OK打完收工!

猜你喜欢

转载自blog.csdn.net/st646889325/article/details/82992599