'statusBarFrame' is deprecated: first deprecated in iOS 13.0 - Use the statusBarManager property of the window scene instead.
在iOS13系统,之前的StatusBar高度获取被弃用,使用UIStatusBarManager来获取StatusBar的状态和属性,由于状态栏高度一般宏定义,所以使用工具类声明方法获取高度,宏定义时调用工具类方法获取,易读性高。
代码实现如下:
#define KStatusBarHeight [UIhelpTools getStatusBarHight]
+ (CGFloat)getStatusBarHight {
float statusBarHeight = 0;
if (@available(iOS 13.0, *)) {
UIStatusBarManager *statusBarManager = [UIApplication sharedApplication].windows.firstObject.windowScene.statusBarManager;
statusBarHeight = statusBarManager.statusBarFrame.size.height;
}
else {
statusBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height;
}
return statusBarHeight;
}
网友评论