| 机型 (iPhone) | 尺寸 (inch) | 像素密度 (ppi) | 缩放因子 (Scale Factor) | 纵横比 (Aspect ratio) | 逻辑分辨率 (pt) | 渲染分辨率 (px) | 屏幕(物理)分辨率 (px) | 竖屏安全区域 (safeAreaInsets) |
|---|---|---|---|---|---|---|---|---|
| 2G/3G/3GS | 3.5 | 165 | 1.0 | 3 : 2 | 320 x 480 | 320 x 480 | 320 x 480 | top: 20 bottom: 0 |
| 4/4s | 3.5 | 330 | 2.0 | 16 : 9 | 320 x 480 | 640 x 960 | 640 x 960 | top: 20 bottom: 0 |
| 5/5c/5s/SE | 4.0 | 326 | 2.0 | 16 : 9 | 320 x 568 | 640 x 1136 | 640 x 1136 | top: 20 bottom: 0 |
| 6/6s/7/8/SE2/SE3 | 4.7 | 326 | 2.0 | 16 : 9 | 375 x 667 | 750 x 1134 | 750 x 1134 | top: 20 bottom: 0 |
| 6P/6s Plus/7P/8P | 5.5 | 401 | 3.0 | 16 : 9 | 414 x 736 | 1242 x 2208 | 1242 x 2208 | top: 20 bottom: 0 |
| X/Xs/11 Pro | 5.8 | 458 | 3.0 | 19 : 9 | 375 x 812 | 1125 x 2436 | 1125 x 2436 | top: 44 bottom: 34 |
| Xr/11/ | 6.1 | 326 | 2.0 | 19 : 9 | 414 x 896 | 828 x 1792 | 828 x 1792 | top: 48 bottom: 34 |
| Xs Max/11 Pro Max | 6.5 | 458 | 3.0 | 19 : 9 | 414 x 896 | 1242 x 2688 | 1242 x 2688 | top: 48 bottom: 34 |
| 12 mini/13 mini | 5.4 | 476 | 3.0 | 19 : 9 | 375 x 812 | 1125 x 2436 | 1080 x 2340 | top: 50 bottom: 34 |
| 12/12 Pro/13/13 Pro/14 | 6.1 | 460 | 3 | 19 : 9 | 390 x 844 | 1170 x 2532 | 1170 x 2532 | top: 47 bottom: 34 |
| 12 Pro Max/13 Pro Max/14 Plus | 6.7 | 458 | 3.0 | 19 : 9 | 428 x 926 | 1248 x 2778 | 1248 x 2778 | top: 47 bottom: 34 |
| 14 Pro | 6.1 | 460 | 3.0 | 19 : 9 | 393 x 852 | 1179 x 2556 | 1179 x 2556 | top: 54 bottom: 34 |
| 14 Pro Max | 6.7 | 460 | 3.0 | 19 : 9 | 430 x 932 | 1290 x 2796 | 1290 x 2796 | top: 59 bottom: 34 |
通常导航栏与tabbar的高度是固定的:
- 导航栏高度:44.0
- tabbar高度:49.0
参考文献:
安全区域偏移量
随着iPhone X 刘海屏机型增多,屏幕尺寸也发生改变,安全距离也不同。竖屏状态下顶部安全距离有20、44、47、48、50、54、59等(今后可能还有其他数值),底部安全距离有0、34(今后可能有其他数值);横竖屏切换时安全距离也不相同:横屏时左右的安全距离相同,由原来竖屏下底部安全距离34改为与顶部安全距离相同。即横屏时左右安全距离相同,都为竖屏下的顶部安全距离。
适配方案:考虑安全区域偏移量,对应处理
// MARK: - 安全区域(不考虑存在导航栏与tabbar的安全区域,因为是取的是window)
public extension UIScreen {
/// 获取根 window
static var lp_window: UIWindow? {
if let window = UIApplication.shared.delegate?.window {
return window
}else{
if #available(iOS 11, *) {
return UIApplication.shared.keyWindow
}else if #available(iOS 13.0, *) {
let scene = UIApplication.shared.connectedScenes.first
let windowScene = scene as? UIWindowScene
return windowScene?.windows.first
}else{
return UIApplication.shared.windows.filter {$0.isKeyWindow}.first
}
}
}
/// main 即将被弃用,故新增API
static var lp_main: UIScreen {
if #available(iOS 16.0, *) {
return lp_window!.screen
}else{
return UIScreen.main
}
}
///状态栏高度
static var lp_statusBarHeight: CGFloat {
if #available(iOS 13.0, *) {
return lp_window?.windowScene?.statusBarManager?.statusBarFrame.size.height ?? 0.0
} else {
return UIApplication.shared.statusBarFrame.size.height
}
}
/// navBar 高度(不考虑安全区域)
static var lp_navBarHeight: CGFloat {
return 44.0
}
/// navBar + 底部安全距离 navBar 安全区域高度
static var lp_safeAreaNavBarHeight: CGFloat {
return lp_navBarHeight + lp_statusBarHeight
}
/// tabbar 高度(不考虑安全区域)
static var lp_tabBarHeight: CGFloat {
if let tabController = UIScreen.lp_window?.rootViewController as? UITabBarController {
return tabController.tabBar.safeAreaLayoutGuide.layoutFrame.height
}
return 49.0
}
/// tabbar + 底部安全距离 tabbar 安全区域高度
static var lp_safeAreaTabBarHeight: CGFloat {
if let tabController = UIScreen.lp_window?.rootViewController as? UITabBarController {
return tabController.tabBar.frame.height
}
return lp_tabBarHeight + lp_safeAreaBottom
}
///安全区域范围
static var lp_safeAreaLayoutFrame: CGRect {
return lp_window?.safeAreaLayoutGuide.layoutFrame ?? .zero
}
///安全距离的Insets
static var lp_safeAreaInsets: UIEdgeInsets {
return lp_window?.safeAreaInsets ?? .zero
}
///顶部安全距离
static var lp_safeAreaTop: CGFloat {
return lp_safeAreaInsets.top
}
///左边安全距离
static var lp_safeAreaLeft: CGFloat {
return lp_safeAreaInsets.bottom
}
///底部安全距离
static var lp_safeAreaBottom: CGFloat {
return lp_safeAreaInsets.bottom
}
///右边安全距离
static var lp_safeAreaRight: CGFloat {
return lp_safeAreaInsets.right
}
///屏幕是否是全面屏(带圆角、刘海的屏幕)
static var isFullScreen: Bool {
return lp_safeAreaBottom > 0 ? true : false
}
}
// MARK: - 屏幕宽高
public extension UIScreen {
static var lp_screenSize: CGSize {
return lp_main.bounds.size
}
///屏幕宽
static var lp_screenWidth: CGFloat {
return lp_screenSize.width
}
///屏幕高
static var lp_screenHeight: CGFloat {
return lp_screenSize.height
}
}
本文介绍了iPhone各机型的安全区域偏移量,包括导航栏和tabbar的标准高度,并强调了iPhone X之后刘海屏带来的屏幕尺寸变化。在竖屏状态下,顶部安全距离有多种数值,底部安全距离通常为34。横屏时,安全距离调整为与顶部相同。适配方案需考虑这些安全区域偏移量。
3138





