关于顶部导航栏
#define SCREEN_HEIGHTL [UIScreen mainScreen].bounds.size.height
#define SCREEN_WIDTHL [UIScreen mainScreen].bounds.size.width
#define Height_StatusBar [[UIApplication sharedApplication] statusBarFrame].size.height
#define Height_NavBar self.navigationController.navigationBar.frame.size.height
#define Height_TopBar (Height_StatusBar+Height_NavBar)
//适配iPhoneXS Max,iPhoneXS,iPhoneXR
判断是否为 iPhoneXS Max,iPhoneXS,iPhoneXR,iPhoneX
#define KIsiPhoneX ((int)((SCREEN_HEIGHTL/SCREEN_WIDTHL)*100) == 216)?YES:NO
//判断是否为 iPhoneXS Max,iPhoneXS,iPhoneXR,iPhoneX
我是根据 iPhoneXS Max,iPhoneXS,iPhoneXR,iPhoneX 的宽高比近似做的判断。
//XSM SCREEN_HEIGHTL = 896.000000,SCREEN_WIDTHL = 414.000000 2.1642512077
//XS SCREEN_HEIGHTL = 812.000000,SCREEN_WIDTHL = 375.000000 2.1653333333
//XR SCREEN_HEIGHTL = 896.000000,SCREEN_WIDTHL = 414.000000 2.1642512077
NSLog(@"SCREEN_HEIGHTL = %f,SCREEN_WIDTHL = %f",SCREEN_HEIGHTL,SCREEN_WIDTHL);
NSLog(@"%d",(int)((SCREEN_HEIGHTL/SCREEN_WIDTHL)*100));
if ((int)((SCREEN_HEIGHTL/SCREEN_WIDTHL)*100) == 216) {
NSLog(@"YES,we can use it!");
}else{
NSLog(@"NO,we can`t use it!");
}
网友评论
另外,建议再加一个 X 系列底部的 34 高度的宏
已经改成下面这种写法
#define Height_StatusBar [[UIApplication sharedApplication] statusBarFrame].size.height
#define Height_NavBar 44.0f
#define Height_TopBar (Height_StatusBar + Height_NavBar)
#define iPhoneX (([[UIApplication sharedApplication] statusBarFrame].size.height == 44.0f) ? (YES):(NO))