iOS|iOS iPhone12&其他机型适配
文章图片
机型 宏
// 判断是否是ipad
#define JH_isPad ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
// 判断iPhone4系列
#define JH_isiPhone4 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) && !JH_isPad : NO)
// 判断iPhone5系列
#define JH_isiPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) && !JH_isPad : NO)
// 判断iPhone6系列
#define JS_isiPhone6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) && !JH_isPad : NO)
//判断iphone6+系列
#define JH_isiPhone6Plus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size) && !JH_isPad : NO)
// 判断iPhoneX
#define JH_isIPhone_X ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) && !JH_isPad : NO)
// 判断iPHoneXr | 11
#define JH_isIPhone_Xr ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(828, 1792), [[UIScreen mainScreen] currentMode].size) && !JH_isPad : NO)
// 判断iPhoneXs | 11Pro
#define JH_isIPhone_Xs ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) && !JH_isPad : NO)
// 判断iPhoneXs Max | 11ProMax
#define JH_isIPhone_Xs_Max ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2688), [[UIScreen mainScreen] currentMode].size) && !JH_isPad : NO)//判断iPhone12_Mini
#define JH_isIPhone_iPhone12_Mini ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1080, 2340), [[UIScreen mainScreen] currentMode].size) && !JH_isPad : NO)//判断iPhone12 | 12Pro
#define JH_isIPhone_iPhone12 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1170, 2532), [[UIScreen mainScreen] currentMode].size) && !JH_isPad : NO)//判断iPhone12 Pro Max
#define JH_isIPhone_iPhone12_ProMax ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1284, 2778), [[UIScreen mainScreen] currentMode].size) && !JH_isPad : NO)//x系列
#define JH_isIPhone_IPhoneX_All (JH_isIPhone_X || JH_isIPhone_Xr || JH_isIPhone_Xs || JH_isIPhone_Xs_Max || JH_isIPhone_iPhone12_Mini || JH_isIPhone_iPhone12 || JH_isIPhone_iPhone12_ProMax)#define Height_StatusBar ((JH_isIPhone_X == YES || JH_isIPhone_Xr == YES || JH_isIPhone_Xs == YES || JH_isIPhone_Xs_Max == YES || JH_isIPhone_iPhone12_Mini == YES) ? 44.0 : 20.0)#define Height_NavBar ((JH_isIPhone_Xr == YES || JH_isIPhone_Xs == YES || JH_isIPhone_Xs_Max == YES || JH_isIPhone_iPhone12_Mini == YES) ? 88.0 : (JH_isIPhone_X == YES) ? 92 : (JH_isIPhone_iPhone12 == YES || JH_isIPhone_iPhone12_ProMax == YES) ? 91 : 64.0)#define Height_TabBar ((JH_isIPhone_IPhoneX_All == YES) ? 83.0 : 49.0)#define Height_bottomSafeArea (JH_isIPhone_IPhoneX_All == YES ? 34.0 : 0.0)/// 等比例适配 以当前设计图为模板
//812.0f----375.0f
#define SCREEN_WIDTH_BILI (SCREEN_WIDTH/375.0f)
#define Width_Real(a) a*SCREEN_WIDTH_BILI#define SCREEN_HEIGHT_BILI (SCREEN_HEIGHT/812.0f)
#define Height_Real(a) a*SCREEN_HEIGHT_BILI
查看
NSLog(@"状态栏高度=%f",[[UIApplication sharedApplication] statusBarFrame].size.height);
NSLog(@"导航栏高度+状态栏高度=%f",self.navigationController.navigationBar.frame.size.height + [[UIApplication sharedApplication] statusBarFrame].size.height);
NSLog(@"Tabbar高度=%f",self.tabBarController.tabBar.bounds.size.height);
推荐阅读
- JAVA(抽象类与接口的区别&重载与重写&内存泄漏)
- 2020-04-07vue中Axios的封装和API接口的管理
- 宋仲基&宋慧乔(我们不公布恋情,我们直接结婚。)
- iOS中的Block
- 21天|21天|M&M《见识》04
- 记录iOS生成分享图片的一些问题,根据UIView生成固定尺寸的分享图片
- 2019-08-29|2019-08-29 iOS13适配那点事
- Hacking|Hacking with iOS: SwiftUI Edition - SnowSeeker 项目(一)
- iOS面试题--基础
- 二叉树路径节点关键值和等于目标值(LeetCode--112&LeetCode--113)