iOS 判断机型是否为 iPhone X、XR、XS、XS Max 的方法

 

// 判断是否为iPhone X 系列  这样写消除了在Xcode10上的警告。
#define IPHONE_X \
({BOOL isPhoneX = NO;\
if (@available(iOS 11.0, *)) {\
isPhoneX = [[UIApplication sharedApplication] delegate].window.safeAreaInsets.bottom > 0.0;\
}\
(isPhoneX);})

原理是根据手机底部安全区的高度 判断是否为 iPhone X、XR、XS、XS Max 几款机型,用宏的方法使用方便,在使用的地方对 IPHONE_X 进行一下判断即可。

/**
 *导航栏高度
 */
#define SafeAreaTopHeight (IPHONE_X ? 88 : 64)

/**
 *tabbar高度
 */
#define SafeAreaBottomHeight (IPHONE_X ? (49 + 34) : 49)

 

你可能感兴趣的:(iOS,开发)