1、判断是否是刘海屏
//判断是否是刘海屏
BOOL isIPhoneNotchScreen(void)
{
if (__IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_11_0) {
return NO;
}
/* iPhone8 Plus UIEdgeInsets: {20, 0, 0, 0}
* iPhone8 UIEdgeInsets: {20, 0, 0, 0}
* iPhone XR UIEdgeInsets: {44, 0, 34, 0}
* iPhone XS UIEdgeInsets: {44, 0, 34, 0}
* iPhone XS Max UIEdgeInsets: {44, 0, 34, 0}
*/
UIEdgeInsets safeAreaInsets = UIApplication.sharedApplication.windows.firstObject.safeAreaInsets;
CGFloat bottomSpace = 0;
switch (UIApplication.sharedApplication.statusBarOrientation) {
case UIInterfaceOrientationPortrait:{
bottomSpace = safeAreaInsets.bottom;
}break;
case UIInterfaceOrientationLandscapeLeft:{
bottomSpace = safeAreaInsets.right;
}break;
case UIInterfaceOrientationLandscapeRight:{
bottomSpace = safeAreaInsets.left;
} break;
case UIInterfaceOrientationPortraitUpsideDown:{
bottomSpace = safeAreaInsets.top;
}break;
default:
bottomSpace = safeAreaInsets.bottom;
break;
}
return bottomSpace > 0 ? YES : NO;
}
2、获取导航栏高度
//获取导航栏高度
CGFloat getNavigationBarHeight(void)
{
if (__IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_11_0) {
return 64.0f;
}
UIEdgeInsets safeAreaInsets = UIApplication.sharedApplication.windows.firstObject.safeAreaInsets;
CGFloat topSpace = 0;
switch (UIApplication.sharedApplication.statusBarOrientation) {
case UIInterfaceOrientationPortrait:{
topSpace = safeAreaInsets.top;
}break;
case UIInterfaceOrientationLandscapeLeft:{
topSpace = safeAreaInsets.left;
}break;
case UIInterfaceOrientationLandscapeRight:{
topSpace = safeAreaInsets.right;
} break;
case UIInterfaceOrientationPortraitUpsideDown:{
topSpace = safeAreaInsets.bottom;
}break;
default:
topSpace = safeAreaInsets.top;
break;
}
return topSpace + 44.0f;
}
3、获取tabBar高度
//获取tabBar高度
CGFloat getTabBarHeight(void)
{
if (__IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_11_0) {
return 49.0;
}
UIEdgeInsets safeAreaInsets = UIApplication.sharedApplication.windows.firstObject.safeAreaInsets;
CGFloat bottomSpace = 0;
switch (UIApplication.sharedApplication.statusBarOrientation) {
case UIInterfaceOrientationPortrait:{
bottomSpace = safeAreaInsets.bottom;
}break;
case UIInterfaceOrientationLandscapeLeft:{
bottomSpace = safeAreaInsets.right;
}break;
case UIInterfaceOrientationLandscapeRight:{
bottomSpace = safeAreaInsets.left;
} break;
case UIInterfaceOrientationPortraitUpsideDown:{
bottomSpace = safeAreaInsets.top;
}break;
default:
bottomSpace = safeAreaInsets.bottom;
break;
}
return bottomSpace + 49.0;
}
网友评论