isIPhoneX 判断条件错误
quanh opened this issue · 2 comments
quanh commented
isIPhoneX 判断是错误的。会误判X系列为非X系列
LChao05 commented
- (BOOL)isIphoneX {
return [[[UIDevice currentDevice] systemVersion] floatValue] >= 11.f && (MIN([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) >= 375 && MAX([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) >= 812);
}
我改了代码
Andy0570 commented
我找到一种方法,可以通过屏幕的高度来判断当前设备是否为异形屏。
实例方法:
- (BOOL)isNotchScreen {
// 判断当前设备类型是否为 iPhone
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
// 获取屏幕的高度
CGFloat screenHeight = [[UIScreen mainScreen] bounds].size.height;
// 目前已知的两个异形屏尺寸:375x812、414x896
if (screenHeight == 812.0f || screenHeight == 896.0f) {
return YES;
}
}
return NO;
}
宏定义方法:
#define IS_NOTCH_SCREEN \
([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) \
&& (([[UIScreen mainScreen] bounds].size.height == 812.0f) \
|| ([[UIScreen mainScreen] bounds].size.height == 896.0f))