iOS屏幕适配-普通机与刘海屏(iPhoneX/XR/XS/XS
2018-10-22 本文已影响608人
雨_田
简介:根据开发工具Xcode10,硬件:苹果放弃4s/5/5c,从se,5s及以上的手机适配;软件:支持iOS8.0及以上系统适配。
一、手机识别
1、硬件编号识别
一款iPhone除了有IPhone XS、XS Max、XR等这样的对外发布手机编号,还有一套对内的iPhone11,2/11,4/11,8等对应的硬件编号
#import <sys/utsname.h>
+ (NSString *)DeviceModel {
struct utsname systemInfo;
uname(&systemInfo);
NSString *deviceString = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
if ([deviceString isEqualToString:@"iPhone1,1"]) return @"Apple#iPhone 1G";
if ([deviceString isEqualToString:@"iPhone1,2"]) return @"Apple#iPhone 3G";
if ([deviceString isEqualToString:@"iPhone2,1"]) return @"Apple#iPhone 3GS";
if ([deviceString isEqualToString:@"iPhone3,1"]) return @"Apple#iPhone 4";
if ([deviceString isEqualToString:@"iPhone3,2"]) return @"Apple#iPhone 4 Verizon";
if ([deviceString isEqualToString:@"iPhone4,1"]) return @"Apple#iPhone 4S";
if ([deviceString isEqualToString:@"iPhone5,2"]) return @"Apple#iPhone 5";
if ([deviceString isEqualToString:@"iPhone5,3"]) return @"Apple#iPhone 5c";
if ([deviceString isEqualToString:@"iPhone5,4"]) return @"Apple#iPhone 5c";
if ([deviceString isEqualToString:@"iPhone6,1"]) return @"Apple#iPhone 5s";
if ([deviceString isEqualToString:@"iPhone6,2"]) return @"Apple#iPhone 5s";
if ([deviceString isEqualToString:@"iPhone7,1"]) return @"Apple#iPhone 6 Plus";
if ([deviceString isEqualToString:@"iPhone7,2"]) return @"Apple#iPhone 6";
if ([deviceString isEqualToString:@"iPhone8,1"]) return @"Apple#iPhone 6s";
if ([deviceString isEqualToString:@"iPhone8,2"]) return @"Apple#iPhone 6s Plus";
if ([deviceString isEqualToString:@"iPhone8,4"]) return @"Apple#iPhone SE";
if ([deviceString isEqualToString:@"iPhone9,1"]) return @"Apple#iPhone 7";
if ([deviceString isEqualToString:@"iPhone9,2"]) return @"Apple#iPhone 7 Plus";
if ([deviceString isEqualToString:@"iPhone9,3"]) return @"Apple#iPhone 7";
if ([deviceString isEqualToString:@"iPhone9,4"]) return @"Apple#iPhone 7 Plus";
if ([deviceString isEqualToString:@"iPhone10,1"]) return @"Apple#iPhone 8 Global";
if ([deviceString isEqualToString:@"iPhone10,2"]) return @"Apple#iPhone 8 Plus Global";
if ([deviceString isEqualToString:@"iPhone10,3"]) return @"Apple#iPhone X Global";
if ([deviceString isEqualToString:@"iPhone10,4"]) return @"Apple#iPhone 8 GSM";
if ([deviceString isEqualToString:@"iPhone10,5"]) return @"Apple#iPhone 8 Plus GSM";
if ([deviceString isEqualToString:@"iPhone10,6"]) return @"Apple#iPhone X GSM";
if ([deviceString isEqualToString:@"iPhone11,2"]) return @"Apple#iPhone XS";
if ([deviceString isEqualToString:@"iPhone11,4"]) return @"Apple#iPhone XS Max (China)";
if ([deviceString isEqualToString:@"iPhone11,6"]) return @"Apple#iPhone XS Max";
if ([deviceString isEqualToString:@"iPhone11,8"]) return @"Apple#iPhone XR";
if ([deviceString isEqualToString:@"i386"]) return @"Apple#Simulator 32";
if ([deviceString isEqualToString:@"x86_64"]) return @"Apple#Simulator 64";
#ifdef DEBUG
NSLog(@"NOTE: Unknown device type: %@", deviceString);
#endif
return [NSString stringWithFormat:@"Apple#%@",deviceString];
}
2、屏幕分辨率识别
iOS分辨率.PNG
二、刘海屏尺寸pt分布
iPhoneX系列.png
三、实际适配宏定义
/**
* MARK:-屏幕尺寸宏定义
* 导航栏高度 状态栏高度 底部tabbar高度 苹果X底部安全区高度
*/
//屏幕rect
#define SCREEN_BOUNDS ([UIScreen mainScreen].bounds)
//屏幕宽度
#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
//屏幕高度
#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)
//屏幕分辨率
#define SCREEN_RESOLUTION (SCREEN_WIDTH * SCREEN_HEIGHT * ([UIScreen mainScreen].scale))
//iPhone X系列判断
#define IS_iPhoneX (CGSizeEqualToSize(CGSizeMake(375.f, 812.f), [UIScreen mainScreen].bounds.size) || CGSizeEqualToSize(CGSizeMake(812.f, 375.f), [UIScreen mainScreen].bounds.size) || CGSizeEqualToSize(CGSizeMake(414.f, 896.f), [UIScreen mainScreen].bounds.size) || CGSizeEqualToSize(CGSizeMake(896.f, 414.f), [UIScreen mainScreen].bounds.size))
//状态栏高度
#define StatusBarHeight (IS_iPhoneX ? 44.f : 20.f)
//导航栏高度
#define NavBarHeight (44.f+StatusBarHeight)
//底部标签栏高度
#define TabBarHeight (IS_iPhoneX ? (49.f+34.f) : 49.f)
//安全区域高度
#define TabbarSafeBottomMargin (IS_iPhoneX ? 34.f : 0.f)
四、启动图适配
启动图适配.png
五、app图标适配
app图标适配.png