iOS14 适配新iPhone 12四种机型
2020-11-17 本文已影响0人
园丁云
GitHub: https://github.com/GardenerYun
Email: gardeneryun@foxmail.com
简书博客地址: http://www.jianshu.com/users/8489e70e237d/latest_articles
如有问题或建议请联系我,我会马上解决问题~ (ง •̀_•́)ง
1、适配新iPhone 12 四种机型
新增四种机型。整理的表格如下:
机型 | 物理分辨率 (pixel) | 逻辑分辨率 (point) | 像素密度 (PPI) | 缩放因子 (切图规格) |
---|---|---|---|---|
iPhone 12 | 1170 × 2532 | 390 × 844 | 460 | @3x |
iPhone 12 Pro | 1170 × 2532 | 390 × 844 | 460 | @3x |
iPhone 12 mini | 1125 × 2436 (1080 × 2340) | 375 × 812 | 476 | @3x(2.88x) |
iPhone 12 Pro Max | 1284 × 2778 | 428 × 926 | 458 | @3x |
iPhone XR | 828 × 1792 | 414 × 896 | 326 | @2x |
iPhone 11 | 828 × 1792 | 414 × 896 | 326 | @2x |
iPhone 11 Pro | 1125 × 2436 | 375 × 812 | 458 | @3x |
iPhone 11Pro Max | 1242 × 2688 | 414 × 896 | 458 | @3x |
iPhone 8 | 750 × 1334 | 375 × 667 | 326 | @2x |
iPhone 8 Plus | 1242 × 2208 (1080 × 1920) | 414 × 736 | 401 | @3x(2.62x) |
iPhone 5s | 640 × 1136 | 320 × 568 | 326 | @2x |
注意:iPhone 12 mini 与 iPhone 6 Plus 机型一样,先由标准的3X,然后系统转成的2.88X / 2.62X.
iPhone 12 mini 逻辑分辨率375 × 812 ,物理分辨率为1125 × 2436,然后系统转成实际分辨率1080 × 2340
iPhone 8 Plus 逻辑分辨率414 × 736 ,物理分辨率为1242 × 2208,然后系统转成实际分辨率1080 × 1920
2、iOS14状态栏高度的改变
在iOS14中无意发现状态栏高度有一定变化,整理如下表格:
注意:使用Xcode12.0.1、Xcode12.1、Xcode12.2 中运行各屏幕模拟器获取的数据。(无iPhone 12真机测试 仅供参考,欢迎讨论)
机型 | 导航栏高度 | 状态栏高度 | 标签栏高度 |
---|---|---|---|
iPhone 12 | 44pt | 47pt | 49pt |
iPhone 12 Pro | 44pt | 47pt | 49pt |
iPhone 12 mini | 44pt | 44pt | 49pt |
iPhone 12 Pro MAX | 44pt | 47pt | 49pt |
iPhone XR | 44pt | 48pt | 49pt |
iPhone 11 | 44pt | 48pt | 49pt |
iPhone 11 Pro | 44pt | 44pt | 49pt |
iPhone 11Pro MAX | 44pt | 44pt | 49pt |
iPhone 8 | 20pt | 44pt | 49pt |
iPhone 8 Plus | 20pt | 44pt | 49pt |
iPhone 5s | 20pt | 44pt | 49pt |
3、宏定义代码
使用系统风格,包括导航栏、状态栏、标签栏的宏定义不写死高度。
仅供参考,欢迎讨论
#define iPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define iPhone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define kMaxScreenLength (MAX(kScreenWidth, kScreenHeight))
#define kMinScreenLength (MIN(kScreenWidth, kScreenHeight))
/**
* 屏幕是否是iPhone4
* iPhone4S
*/
#define iPhone4 (iPhone && kMaxScreenLength == 480)
/**
* 屏幕是否是iPhone 5
* iPhone 5S
* iPhone SE 1
*/
#define iPhone5 (iPhone && kMaxScreenLength == 568)
/**
* 屏幕是否是iPhone 6
* iPhone 6S
* iPhone 7
* iPhone 8
* iPhone SE 2
*/
#define iPhone6 (iPhone && kMaxScreenLength == 667)
/**
* 屏幕是否是iPhone 6 Plus
* iPhone 6S Plus
* iPhone 7 Plus
* iPhone 8 Plus
*
*/
#define iPhone6Plus (iPhone && kMaxScreenLength == 736)
/**
* 屏幕是否是iPhone X
* iPhone XS
* iPhone 11 Pro
* iPhone 12 mini
*/
#define iPhoneX (iPhone && kMaxScreenLength == 812)
/**
* 屏幕是否是iPhone XR
* iPhone XS Max
* iPhone 11
* iPhone 11 Pro Max
*/
#define iPhoneXSMax (iPhone && kMaxScreenLength == 896)
/**
* 屏幕是否是iPhone 12
*/
#define iPhone12 (iPhone && kMaxScreenLength == 844)
/**
* 屏幕是否是iPhone 12 Pro Max
*/
#define iPhone12ProMax (iPhone && kMaxScreenLength == 926)
/**
* 屏幕高度
*/
#define kScreenHeight ([UIScreen mainScreen].bounds.size.height)
/**
* 屏幕宽度
*/
#define kScreenWidth ([UIScreen mainScreen].bounds.size.width)
/**
* 状态栏
*/
#define kStatusBarHeight [[UIApplication sharedApplication] statusBarFrame].size.height
/**
* 导航栏
*/
#define kNavigationBarHeight [[UINavigationController alloc] init].navigationBar.frame.size.height
/**
* 标签栏
*/
#define kTabBarHeight [[UITabBarController alloc] init].tabBar.frame.size.height
/**
* 竖屏底部安全区域
*/
#define kSafeAreaHeight \
({CGFloat bottom=0.0;\
if (@available(iOS 11.0, *)) {\
bottom = [[UIApplication sharedApplication] delegate].window.safeAreaInsets.bottom;\
} else { \
bottom=0;\
}\
(bottom);\
})