#define STATUS_H_F \
({\
CGFloat statusBarHeight = 0;\
if (@available(iOS 13.0, *)) {\
CGFloat topPadding = [UIApplication sharedApplication].windows.firstObject.safeAreaInsets.top;\
statusBarHeight = topPadding == 0 ? 20.0 : topPadding;\
} else {\
statusBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height;\
}\
(statusBarHeight);\
}) //状态栏高度
上述方法,在web使用video标签全屏播放视频后,获取到[UIApplication sharedApplication].windows.firstObject.safeAreaInsets.top为0,导致自定义导航栏页面上移,不明所以然。优化后以下代码更为科学:
#define STATUS_H_F \
({\
CGFloat statusBarHeight = 0;\
if (@available(iOS 13.0, *)) {\
NSSet *set = [UIApplication sharedApplication].connectedScenes;\
UIWindowScene *windowScene = [set anyObject];\
UIStatusBarManager *statusBarManager = windowScene.statusBarManager;\
statusBarHeight = statusBarManager.statusBarFrame.size.height;\
} else {\
statusBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height;\
}\
(statusBarHeight);\
}) //状态栏高度