可通过代码获取状态栏高度:
CGFloat statusBarHeight = 0.f;
if (@available(iOS 13.0, *)) {
statusBarHeight = [UIApplication sharedApplication].keyWindow.windowScene.statusBarManager.statusBarFrame.size.height;
} else {
statusBarHeight = [[UIApplication sharedApplication] statusBarFrame].size.height;
}
注意:如果隐藏了状态栏,statusBarFrame为CGRectZero,上面代码取到的高度就是 0.f 。