iPhone 全机型分辨率和尺寸大全

本文介绍了iPhone各机型的安全区域偏移量,包括导航栏和tabbar的标准高度,并强调了iPhone X之后刘海屏带来的屏幕尺寸变化。在竖屏状态下,顶部安全距离有多种数值,底部安全距离通常为34。横屏时,安全距离调整为与顶部相同。适配方案需考虑这些安全区域偏移量。
  
机型
(iPhone)
尺寸
(inch)
像素密度
(ppi)
缩放因子
(Scale Factor)
纵横比
(Aspect ratio)
逻辑分辨率
(pt)
渲染分辨率
(px)
屏幕(物理)分辨率
(px)
竖屏安全区域
(safeAreaInsets)
2G/3G/3GS3.51651.03 : 2320 x 480320 x 480320 x 480top: 20
bottom: 0
4/4s3.53302.016 : 9320 x 480640 x 960640 x 960top: 20
bottom: 0
5/5c/5s/SE4.03262.016 : 9320 x 568640 x 1136640 x 1136top: 20
bottom: 0
6/6s/7/8/SE2/SE34.73262.016 : 9375 x 667750 x 1134750 x 1134top: 20
bottom: 0
6P/6s Plus/7P/8P5.54013.016 : 9414 x 7361242 x 22081242 x 2208top: 20
bottom: 0
X/Xs/11 Pro5.84583.019 : 9375 x 8121125 x 24361125 x 2436top: 44
bottom: 34
Xr/11/6.13262.019 : 9414 x 896828 x 1792828 x 1792top: 48
bottom: 34
Xs Max/11 Pro Max6.54583.019 : 9414 x 8961242 x 26881242 x 2688top: 48
bottom: 34
12 mini/13 mini5.44763.019 : 9375 x 8121125 x 24361080 x 2340top: 50
bottom: 34
12/12 Pro/13/13 Pro/146.1460319 : 9390 x 8441170 x 25321170 x 2532top: 47
bottom: 34
12 Pro Max/13 Pro Max/14 Plus6.74583.019 : 9428 x 9261248 x 27781248 x 2778top: 47
bottom: 34
14 Pro6.14603.019 : 9393 x 8521179 x 25561179 x 2556top: 54
bottom: 34
14 Pro Max6.74603.019 : 9430 x 9321290 x 27961290 x 2796top: 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
    }
}
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值