iPhoneX系列适配

iPhone X系列屏幕相关信息:

设备 屏幕尺寸 点分辨率pt 屏幕比例scale 像素分辨率px
iPhone X & iPhone XS 5.8 375 x 812 @3x 1125 x 2436
iPhoneXR 6.1 414 x 896 @2x 828 x 1792
iPhone XS Max 6.5 414 x 896 @3x 1242 x2688

1.启动图适配:
iPhone XR:828px x 1792px
iPhone XS Max: 1242px x 2688px

2.判断iPhone X系列参考方法:

- (BOOL)isIPhoneXSeries {
    BOOL iPhoneXSeries = NO;
    if (UIDevice.currentDevice.userInterfaceIdiom != UIUserInterfaceIdiomPhone) {
        return iPhoneXSeries;
    }
    
    if (@available(iOS 11.0, *)) {
        UIWindow *mainWindow = [[[UIApplication sharedApplication] delegate] window];
        if (mainWindow.safeAreaInsets.bottom > 0.0) {
            iPhoneXSeries = YES;
        }
    }
    
    return iPhoneXSeries;
}

3.iPhone X系列手机设备型号判断:
参考设备型号

if ([platform isEqualToString:@"iPhone10,3"] || [platform isEqualToString:@"iPhone10,6"]) return @"iPhone X";
if ([platform isEqualToString:@"iPhone11,8"]) return @"iPhone XR";
if ([platform isEqualToString:@"iPhone11,2"]) return @"iPhone XS";
if ([platform isEqualToString:@"iPhone11,4"] || [platform isEqualToString:@"iPhone11,6"]) return @"iPhone XS Max";

4.Xcode10升级
google

iOS开发之适配的相关属性

//竖屏状态栏高度
#define Portrait_Status_SafeArea_Height (kDeviceInfo.isiPhoneXSeries ? 44 : 20)
//竖屏底部不带tabbar安全区域高度
#define Portrait_Bottom_SafeArea_Height (kDeviceInfo.isiPhoneXSeries ? 34 : 0)
//竖屏底部带tabbar时安全区域高度
#define Portrait_Tabbar_SafeArea_Height (kDeviceInfo.isiPhoneXSeries ? (49 + 34) : 49)
//横屏底部安全区域的高度
#define Landscal_Bottom_SafeArea_Height (kDeviceInfo.isiPhoneXSeries ? 21 : 0)
//横屏左右安全区域的宽度
#define Landscal_LeftRight_SafeArea_Width (kDeviceInfo.isiPhoneXSeries ? 44 : 49)

你可能感兴趣的:(iPhoneX系列适配)