由于iPhoneX系列手机的出现,导航栏和标签栏的高度不能写死,需要通过代码判断设备类型。随着iPhone X标配的iOS 11出现了safeArea的概念,可以通过safeArea获取导航栏和标签栏高度,当然低于iOS 11的肯定是正常的机型了。
// 屏幕大小
#define ScreenBounds [UIScreen mainScreen].bounds
#define ScreenWidth [UIScreen mainScreen].bounds.size.width
#define ScreenHeight [UIScreen mainScreen].bounds.size.height
// 屏幕宽度比例
#define ScaleWidth (ScreenWidth / 375.0f)
#define ScaleHeight (ScreenHeight / 667.0f)
#define ScaleSize ScaleWidth
// 状态栏高度
#define StatusBarHeight [[UIApplication sharedApplication] statusBarFrame].size.height
// 导航栏高度
#define NavigationBarHeight (StatusBarHeight + 44)
// 标签栏高度
#define TabBarHeight ([Tools bottmHeight] + 49)
// 标签栏高度
#define BottomHeight [Tools bottmHeight]
// 判断是否是iPhone X
#define IS_iPhoneX [Tools isIphoneX]
// 判断是否是小屏幕
#define IS_iPhoneSE (ScreenWidth < 375)
+ (BOOL)isIphoneX;
+ (CGFloat)bottmHeight;
+ (BOOL)isIphoneX {
BOOL isIphoneX = NO;
if (@available(iOS 11.0, *)) {
UIWindow *mainWindow = [[[UIApplication sharedApplication] delegate] window];
if (mainWindow.safeAreaInsets.bottom > 0.0) {
isIphoneX = YES;
}
}
return isIphoneX;
}
+ (CGFloat)bottmHeight {
if (@available(iOS 11.0, *)) {
UIWindow *mainWindow = [[[UIApplication sharedApplication] delegate] window];
return mainWindow.safeAreaInsets.bottom;
}
return 0;
}