刘海屏出来前
- 状态栏:20pt
- 导航栏:44pt
- 底部安全距离:0pt
- tabBar: 49
刘海屏出来后
- 状态栏:44pt
- 导航栏:44pt
- 底部安全距离:34pt
- tabBar: 49
代码
let statusBarHeight = UIApplication.shared.statusBarFrame.height;
let navigationHeight = (statusBarHeight + 44)
let tabBarHeight = (statusBarHeight==44 ? 83 : 49)
let topSafeAreaHeight = (statusBarHeight - 20)
let bottomSafeAreaHeight = (tabBarHeight - 49)
extension UIWindow {
func jx_layoutInsets() -> UIEdgeInsets {
if #available(iOS 11.0, *) {
let safeAreaInsets: UIEdgeInsets = self.safeAreaInsets
if safeAreaInsets.bottom > 0 {
return safeAreaInsets
}
return UIEdgeInsets.init(top: 20, left: 0, bottom: 0, right: 0)
}
return UIEdgeInsets.init(top: 20, left: 0, bottom: 0, right: 0)
}
func jx_navigationHeight() -> CGFloat {
let statusBarHeight = jx_layoutInsets().top
return statusBarHeight + 44
}
}
参考博客:
iOS灵活适配刘海屏手机的顶部状态栏高度和底部安全距离