GitHub: https://github.com/GardenerYun
Email: gardeneryun@foxmail.com
簡(jiǎn)書博客地址: http://www.itdecent.cn/users/8489e70e237d/latest_articles
如有問題或建議請(qǐng)聯(lián)系我,我會(huì)馬上解決問題~ (? ??_??)?
2024-09-25更新;
iPhone 16機(jī)型系列更新
2023-10-27更新;
iPhone 14 、 iPhone 15 機(jī)型見下表
2021-10-26更新;
iPhone 13四種機(jī)型與iPhone 12屏幕大小、分辨率、像素密度完全一致。見下表
1、適配新iPhone 12 四種機(jī)型
新增四種機(jī)型。整理的表格如下:
| 機(jī)型 | 物理分辨率 (pixel) | 邏輯分辨率 (point) | 像素密度 (PPI) | 縮放因子 (切圖規(guī)格) | 狀態(tài)欄高度 |
|---|---|---|---|---|---|
| iPhone 5s/se1 | 640 × 1136 | 320 × 568 | 326 | @2x | 20 |
| iPhone 6/6s/7/8/se2/se3 | 750 × 1334 | 375 × 667 | 326 | @2x | 20 |
| iPhone 6/6s/7/8 Plus | 1242 × 2208 (1080 × 1920) | 414 × 736 | 401 | @3x(2.62x) | 20 |
| iPhone X/XS/11 Pro | 1125 × 2436 | 375 × 812 | 458 | @3x | 44 |
| iPhone XR/11 | 828 × 1792 | 414 × 896 | 326 | @2x | 48 |
| iPhone XS Max/11Pro Max | 1242 × 2688 | 414 × 896 | 458 | @3x | 44 |
| iPhone 12/13/14/12 Pro/13 Pro | 1170 × 2532 | 390 × 844 | 460 | @3x | 47 |
| iPhone 12/13 mini | 1125 × 2436 (1080 × 2340) | 375 × 812 | 476 | @3x(2.88x) | 44 |
| iPhone 12/13 Pro Max/14 Plus | 1284 × 2778 | 428 × 926 | 458 | @3x | 47 |
| iPhone 14 Pro/15/15 Pro/16 | 1179 × 2556 | 393 × 852 | 460 | @3x | 54 |
| iPhone 14 Pro Max/15 Plus/15 Pro Max/16 Plus | 1290 × 2796 | 430 × 932 | 460 | @3x | 54 |
| iPhone 16 Pro | 1206 x 2622 | 402 x 874 | 460 | @3x | 54 |
| iPhone 16 Pro Max | 1320 x 2868 | 440 x 956 | 460 | @3x | 54 |
注意:iPhone 12 mini 與 iPhone 6 Plus 機(jī)型一樣,先由標(biāo)準(zhǔn)的3X,然后系統(tǒng)轉(zhuǎn)成的2.88X / 2.62X.
iPhone 12 mini 邏輯分辨率375 × 812 ,物理分辨率為1125 × 2436,然后系統(tǒng)轉(zhuǎn)成實(shí)際分辨率1080 × 2340
iPhone 8 Plus 邏輯分辨率414 × 736 ,物理分辨率為1242 × 2208,然后系統(tǒng)轉(zhuǎn)成實(shí)際分辨率1080 × 1920
2、iOS14狀態(tài)欄高度的改變(統(tǒng)一維護(hù)在上表)
在iOS14中無意發(fā)現(xiàn)狀態(tài)欄高度有一定變化,整理如下表格:
注意:使用Xcode12.0.1、Xcode12.1、Xcode12.2 中運(yùn)行各屏幕模擬器獲取的數(shù)據(jù)。(無iPhone 12真機(jī)測(cè)試 僅供參考,歡迎討論)
| 機(jī)型 | 導(dǎo)航欄高度 | 狀態(tài)欄高度 | 標(biāo)簽欄高度 |
|---|---|---|---|
| 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 | 44pt | 20pt | 49pt |
| iPhone 8 Plus | 44pt | 20pt | 49pt |
| iPhone 5s | 44pt | 20pt | 49pt |
3、宏定義代碼
使用系統(tǒng)風(fēng)格,包括導(dǎo)航欄、狀態(tài)欄、標(biāo)簽欄的宏定義不寫死高度。
僅供參考,歡迎討論
#define iOS12 ([[UIDevice currentDevice].systemVersion floatValue] >= 12.0)
#define iOS13 ([[UIDevice currentDevice].systemVersion floatValue] >= 13.0)
#define iOS14 ([[UIDevice currentDevice].systemVersion floatValue] >= 14.0)
#define iOS15 ([[UIDevice currentDevice].systemVersion floatValue] >= 15.0)
#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
* iPhone SE 3
*/
#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
* iPhone 13 mini
*/
#define iPhoneX (iPhone && kMaxScreenLength == 812)
/**
* 屏幕是否是iPhone XR
* iPhone XS Max
* iPhone 11
* iPhone 11 Pro Max
*/
#define iPhoneXSMax (iPhone && kMaxScreenLength == 896)
/**
* 屏幕是否是iPhone 12
* 屏幕是否是iPhone 12 Pro
* 屏幕是否是iPhone 13
* 屏幕是否是iPhone 13 Pro
* 屏幕是否是iPhone 14
*/
#define iPhone12 (iPhone && kMaxScreenLength == 844)
/**
* 屏幕是否是iPhone 12 Pro Max
* 屏幕是否是iPhone 13 Pro Max
* 屏幕是否是iPhone 14 Plus
*/
#define iPhone12ProMax (iPhone && kMaxScreenLength == 926)
/**
* 屏幕是否是iPhone 14 Pro
* 屏幕是否是iPhone 15
* 屏幕是否是iPhone 15 Pro
*/
#define iPhone14 Pro (iPhone && kMaxScreenLength == 852)
/**
* 屏幕是否是iPhone 14 Pro Max
* 屏幕是否是iPhone 15 Plus
* 屏幕是否是iPhone 15 Pro Max
*/
#define iPhone14ProMax (iPhone && kMaxScreenLength == 932)
/**
* 屏幕是否是iPhoneX及更新系列
*/
#define iPhoneXAndNewer (kSafeAreaHeight>0 && (iPhone && kMaxScreenLength >= 812))
/**
* 屏幕高度
*/
#define kScreenHeight ([UIScreen mainScreen].bounds.size.height)
/**
* 屏幕寬度
*/
#define kScreenWidth ([UIScreen mainScreen].bounds.size.width)
/**
* 狀態(tài)欄
*/
#define kStatusBarHeight [[UIApplication sharedApplication] statusBarFrame].size.height
/**
* 導(dǎo)航欄
*/
#define kNavigationBarHeight [[UINavigationController alloc] init].navigationBar.frame.size.height
/**
* 標(biāo)簽欄
*/
#define kTabBarHeight [[UITabBarController alloc] init].tabBar.frame.size.height
#define WeakSelf __weak typeof(self) weakSelf = self;
#define StrongSelf __strong __typeof__(self) strongSelf = self;
/**
* 豎屏底部安全區(qū)域
*/
#define kSafeAreaHeight \
({CGFloat bottom=0.0;\
if (@available(iOS 11.0, *)) {\
bottom = [[UIApplication sharedApplication] delegate].window.safeAreaInsets.bottom;\
} else { \
bottom=0;\
}\
(bottom);\
})