1. 程式人生 > >iPhoneX、iPhoneXS、iPhoneXR、iPhoneXSMax螢幕適配

iPhoneX、iPhoneXS、iPhoneXR、iPhoneXSMax螢幕適配

蘋果所有裝置螢幕尺寸

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打完收工!