iOS: hasNotch implements

This commit is contained in:
王劲鹏 2020-03-19 11:52:02 +08:00 committed by osborn
parent b626eb3071
commit ef0e53a7ac
3 changed files with 12 additions and 0 deletions

View File

@ -68,6 +68,7 @@ - (instancetype)init {
@"screenWidth": @([[UIScreen mainScreen] bounds].size.width), @"screenWidth": @([[UIScreen mainScreen] bounds].size.width),
@"screenHeight": @([[UIScreen mainScreen] bounds].size.height), @"screenHeight": @([[UIScreen mainScreen] bounds].size.height),
@"statusBarHeight": @([[UIApplication sharedApplication] statusBarFrame].size.height), @"statusBarHeight": @([[UIApplication sharedApplication] statusBarFrame].size.height),
@"hasNotch": @(hasNotch()),
@"deviceBrand": @"Apple", @"deviceBrand": @"Apple",
@"deviceModel": platform, @"deviceModel": platform,
}; };

View File

@ -42,3 +42,5 @@ NSBundle *_Nonnull DoricBundle(void);
void ShowToast(NSString *_Nonnull text, DoricGravity gravity); void ShowToast(NSString *_Nonnull text, DoricGravity gravity);
UIImage *_Nonnull UIImageWithColor(UIColor *_Nonnull color); UIImage *_Nonnull UIImageWithColor(UIColor *_Nonnull color);
BOOL hasNotch(void);

View File

@ -95,3 +95,12 @@ void ShowToast(NSString *text, DoricGravity gravity) {
UIGraphicsEndImageContext(); UIGraphicsEndImageContext();
return image; return image;
} }
BOOL hasNotch() {
if (@available(iOS 11.0, *)) {
CGFloat height = [[UIApplication sharedApplication] delegate].window.safeAreaInsets.bottom;
return (height > 0);
} else {
return NO;
}
}