iOS 14 系統(tǒng)之后召嘶,劉海屏手機(jī)的狀態(tài)欄高度就不再統(tǒng)一是 44 了。下表是 iOS 15.2 上各劉海屏機(jī)型的狀態(tài)欄高度哮缺,其中 iPhone 13 系列和 iPhone 12 系列是一致的弄跌,就不再重復(fù)列舉。
機(jī)型 | 狀態(tài)欄高度 |
---|---|
iPhone XR/11 | 48 |
iPhone X/11 Pro/ 11 Pro Max/12 mini | 44 |
iPhone 12/12 Pro/Pro Max | 47 |
UIDevice+XPAddition.swift
extension UIDevice {
/// 頂部安全區(qū)高度
static func xp_safeDistanceTop() -> CGFloat {
if #available(iOS 13.0, *) {
let scene = UIApplication.shared.connectedScenes.first
guard let windowScene = scene as? UIWindowScene else { return 0 }
guard let window = windowScene.windows.first else { return 0 }
return window.safeAreaInsets.top
} else if #available(iOS 11.0, *) {
guard let window = UIApplication.shared.windows.first else { return 0 }
return window.safeAreaInsets.top
}
return 0;
}
/// 底部安全區(qū)高度
static func xp_safeDistanceBottom() -> CGFloat {
if #available(iOS 13.0, *) {
let scene = UIApplication.shared.connectedScenes.first
guard let windowScene = scene as? UIWindowScene else { return 0 }
guard let window = windowScene.windows.first else { return 0 }
return window.safeAreaInsets.bottom
} else if #available(iOS 11.0, *) {
guard let window = UIApplication.shared.windows.first else { return 0 }
return window.safeAreaInsets.bottom
}
return 0;
}
/// 頂部狀態(tài)欄高度(包括安全區(qū))
static func xp_statusBarHeight() -> CGFloat {
var statusBarHeight: CGFloat = 0
if #available(iOS 13.0, *) {
let scene = UIApplication.shared.connectedScenes.first
guard let windowScene = scene as? UIWindowScene else { return 0 }
guard let statusBarManager = windowScene.statusBarManager else { return 0 }
statusBarHeight = statusBarManager.statusBarFrame.height
} else {
statusBarHeight = UIApplication.shared.statusBarFrame.height
}
return statusBarHeight
}
/// 導(dǎo)航欄高度
static func xp_navigationBarHeight() -> CGFloat {
return 44.0
}
/// 狀態(tài)欄+導(dǎo)航欄的高度
static func xp_navigationFullHeight() -> CGFloat {
return UIDevice.xp_statusBarHeight() + UIDevice.xp_navigationBarHeight()
}
/// 底部導(dǎo)航欄高度
static func xp_tabBarHeight() -> CGFloat {
return 49.0
}
/// 底部導(dǎo)航欄高度(包括安全區(qū))
static func xp_tabBarFullHeight() -> CGFloat {
return UIDevice.xp_tabBarHeight() + UIDevice.xp_safeDistanceBottom()
}
}