iOS 14 系統(tǒng)之后吃溅,劉海屏手機的狀態(tài)欄高度就不再統(tǒng)一是 44 了。下表是 iOS 15.2 上各劉海屏機型的狀態(tài)欄高度鸯檬,其中 iPhone 13 系列和 iPhone 12 系列是一致的决侈,就不再重復(fù)列舉。
機型 | 狀態(tài)欄高度 |
---|---|
iPhone XR/11 | 48 |
iPhone X/11 Pro/ 11 Pro Max/12 mini | 44 |
iPhone 12/12 Pro/Pro Max | 47 |
// 系統(tǒng)預(yù)留的快速通道(判斷系統(tǒng)版本)喧务,推薦使用:
if #available(iOS 8.0, *) {
//系統(tǒng)版本高于8.0
} else {
//系統(tǒng)版本低于8.0
}
各種常用的命令宏:狀態(tài)欄高度等等(Objective-C赖歌、Swift)
下面??,就寫一個類擴展:
UIDevice+K_Addition.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()
}
}