神剑若水哥:iOS 开发,手机屏幕尺寸和导航条高度

iOS 开发,苹果手机屏幕尺寸和导航条,状态条,高度

统计如下:

手机型号 尺寸(对角线) 物理点 宽长比例 像素点 倍数 状态栏高度 底部安全距离 导航栏高度 tabbar高度 状态条高度
iPhone 4/4S 3.5英寸 320x480 0.667 640x960 @2x 20 - 44 49 20
iPhone 5/5S/5C 4英寸 320x568 0.563 640x1136 @2x 20 - 44 49 20
iPhone SE 4英寸 320x568 0.563 640x1136 @2x 20 - 44 49 20
iPhone 6 4.7英寸 375x667 0.562 750x1334 @2x 20 44 49 20
iPhone 6 Plus 5.5英寸 414x736 0.563 1242x2208 @3x 20 - 44 49 20
iPhone 6S 4.7英寸 375x667 0.562 750x1334 @2x 20 - 44 49 20
iPhone 6S Plus 5.5英寸 414x736 0.563 1242x2208 @3x 20 - 44 49 20
iPhone 7 4.7英寸 375x667 0.562 750x1334 @2x 20 44 49 20
iPhone 7 Plus 5.5英寸 414x736 0.563 1242x2208 @3x 20 - 44 49 20
iPhone 8 4.7英寸 375x667 0.562 750x1334 @2x 20 - 44 49 20
iPhone 8 Plus 5.5英寸 414x736 0.563 1242x2208 @3x 20 - 44 49 20
iPhone X 5.8英寸 375x812 0.462 1125x2436 @3x 44 34 44 83 44
iPhone XS 5.8英寸 375x812 0.462 1125x2436 @3x 44 34 44 83 44
iPhone XR 6.1英寸 414x896 0.462 828x1792 @2x 44 34 44 83 44
iPhone XS Max 6.5英寸 414x896 0.462 1242x2688 @3x 44 34 44 83 44
iPhone 11 Pro 5.8英寸 375x812 0.462 1125x2436 @3x 44 34 44 83 44
iPhone 11 6.1英寸 414x896 0.462 828x1792 @2x 44 34 44 83 44
iPhone 11 Pro Max 6.5英寸 414x896 0.462 1242x2688 @3x 44 34 44 83 44

总结:

iPhoneX 以后的手机 状态条44, 分栏条(tabbar) 83

iPhoneX 以前的手机 状态条20,分栏条(tabbar) 49

导航条永远都是44

所以,如果是纯代码编写的工程项目,适配起来相对容易。

iPone所需要的LaunchImage的尺寸为:

1242*2688

1125*2436

828*1792

1242*2208

750*1334

640*1136

320*480

苹果所有机型对应的machine型号:

machine型号 手机型号
iPhone3,1 iPhone 4 (GSM)
iPhone3,2 iPhone 4 (GSM Rev. A)
iPhone3,3 iPhone 4 (CDMA)
iPhone4,1 iPhone4s
iPhone5,1 iPhone 5 (GSM)
iPhone5,2 iPhone 5 (Global)
iPhone5,3 iPhone 5C (GSM)
iPhone5,4 iPhone 5C (Global)
iPhone6,1 iPhone 5S (GSM)
iPhone6,2 iPhone 5S (Global)
iPhone7,1 iPhone 6Plus
iPhone7,2 iPhone 6
iPhone8,1 iPhone 6s
iPhone8,2 iPhone 6s Plus
iPhone8,4 iPhone SE
iPhone9,1 iPhone 7
iPhone9,3 iPhone 7
iPhone9,2 iPhone 7Plus
iPhone9,4 iPhone 7Plus
iPhone10,1 iPhone 8
iPhone10,4 iPhone 8
iPhone10,2 iPhone 8Plus
iPhone10,5 iPhone 8Plus
iPhone10,3 iPhone X
iPhone10,6 iPhone X
iPhone11,2 iPhone XS
iPhone11,8 iPhone XR
iPhone11,6 iPhone XS Max
iPhone12,1 iPhone 11
iPhone12,3 iPhone 11 Pro
iPhone12,5 iPhone 11 Pro Max

苹果X以上的升级对应关系

年份 主机型
2017年 iPhone X
2018年 iPhone XS iPhone XR iPhone XS Max
2019年 iPhone 11 Pro iPhone 11 iPhone 11 Pro Max

获取的高度数据的代码如下:

#define K_SCREEN_WIDTH                  ([[[UIDevice currentDevice] systemVersion] intValue] >= 7 ? [UIScreen mainScreen].bounds.size.width : [UIScreen mainScreen].applicationFrame.size.width)
#define K_SCREEN_HEIGHT                 ([[[UIDevice currentDevice] systemVersion] intValue] >= 7 ? [UIScreen mainScreen].bounds.size.height : [UIScreen mainScreen].applicationFrame.size.height)

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    NSLog(@"宽度%.f",K_SCREEN_WIDTH);
    NSLog(@"高度%.f",K_SCREEN_HEIGHT);
    NSLog(@"状态条%.f",[[UIApplication sharedApplication] statusBarFrame].size.height);
    NSLog(@"导航条%.f",self.mNavigatonVC.navigationBar.frame.size.height);
    NSLog(@"Tabar%.f",self.mTabbarVC.tabBar.bounds.size.height);
}

适配代码,机型定义:

//手机类型
typedef NS_OPTIONS (NSUInteger, IPhoneSceenType) {
    IPhoneSceenType_4s          =1<< 0,                                                          //4s 或者4
    IPhoneSceenType_5s          =1<< 1,                                                          //5或者5
    IPhoneSceenType_6s          =1<< 2,                                                          //6s或者6或者7或者8
    IPhoneSceenType_6Plus       =1<< 3,                                                          //6Plus或者7Plus或者8Plus
    IPhoneSceenType_IponeX      =1<< 4,                                                          //苹果X/XS/iPhone11_Pro
    IPhoneSceenType_IponeXR     =1<< 5,                                                          //苹果XR,苹果XS_MAX,iPhone11,iPhone11_Pro_Max
    IPhoneSceenType_UnKnown     =1<< 10,                                                         //未知机型
};

机型判断

+ (IPhoneSceenType)getCurrentIPhoneType
{
    if (K_SCREEN_WIDTH  == 320 && K_SCREEN_HEIGHT == 480) {
        return IPhoneSceenType_4s;
    } else if (K_SCREEN_WIDTH  == 320 && K_SCREEN_HEIGHT == 568) {
        return IPhoneSceenType_5s;
    } else if (K_SCREEN_WIDTH  == 375 && K_SCREEN_HEIGHT == 667) {
        return IPhoneSceenType_6s;
    } else if (K_SCREEN_WIDTH  == 414 && K_SCREEN_HEIGHT == 736) {
        return IPhoneSceenType_6Plus;
    } else if (K_SCREEN_WIDTH  == 375 && K_SCREEN_HEIGHT == 812) {
        return IPhoneSceenType_IponeX;
    } else if (K_SCREEN_WIDTH  == 414 && K_SCREEN_HEIGHT == 896) {
        return IPhoneSceenType_IponeXR;
    } else {
        return IPhoneSceenType_UnKnown;
    }
}

状态条statusBar高度

+(CGFloat)getStatusBarHeight
{
    IPhoneSceenType type = [FZTools getCurrentIPhoneType];
   NSNumber * typeNumber = [NSNumber numberWithInteger:type];
    NSSet *set1 = [[NSSet alloc]initWithArray:@[
        [NSNumber numberWithInt:IPhoneSceenType_4s],
        [NSNumber numberWithInt:IPhoneSceenType_5s],
        [NSNumber numberWithInt:IPhoneSceenType_6s],
        [NSNumber numberWithInt:IPhoneSceenType_6Plus],
    ]];
    NSSet *set2 = [[NSSet alloc]initWithArray:@[
        [NSNumber numberWithInt:IPhoneSceenType_IponeX],
        [NSNumber numberWithInt:IPhoneSceenType_IponeXR],
        [NSNumber numberWithInt:IPhoneSceenType_UnKnown],
    ]];
    if([set1 containsObject:typeNumber]){
        return 20;
    }else if([set2 containsObject:typeNumber]){
        return 44;
    }else{
        return 44;
    }
    
}

分栏选择条的高度

+(CGFloat)getTabbarHeight
{
    IPhoneSceenType type = [FZTools getCurrentIPhoneType];
   NSNumber * typeNumber = [NSNumber numberWithInteger:type];
    NSSet *set1 = [[NSSet alloc]initWithArray:@[
        [NSNumber numberWithInt:IPhoneSceenType_4s],
        [NSNumber numberWithInt:IPhoneSceenType_5s],
        [NSNumber numberWithInt:IPhoneSceenType_6s],
        [NSNumber numberWithInt:IPhoneSceenType_6Plus],
    ]];
    NSSet *set2 = [[NSSet alloc]initWithArray:@[
        [NSNumber numberWithInt:IPhoneSceenType_IponeX],
        [NSNumber numberWithInt:IPhoneSceenType_IponeXR],
        [NSNumber numberWithInt:IPhoneSceenType_UnKnown],
    ]];
    if([set1 containsObject:typeNumber]){
        return 49;
    }else if([set2 containsObject:typeNumber]){
        return 83;
    }else{
        return 83;
    }
}

宏定义

屏幕宽高

#define K_SCREEN_WIDTH                  ([[[UIDevice currentDevice] systemVersion] intValue] >= 7 ? [UIScreen mainScreen].bounds.size.width : [UIScreen mainScreen].applicationFrame.size.width)
#define K_SCREEN_HEIGHT                 ([[[UIDevice currentDevice] systemVersion] intValue] >= 7 ? [UIScreen mainScreen].bounds.size.height : [UIScreen mainScreen].applicationFrame.size.height)

导航条状态条的高度

#define Height_NavBar          44.0f                                    //导航条的高度
#define Height_StatusBar       [FZTools getStatusBarHeight]             //状态条高度
#define Height_TabBar          [FZTools getTabbarHeight]                //tabbar 高度

总结:关于状态条,导航条,tabbar的高度,只要取上面的宏定义就可以啦

你可能感兴趣的:(神剑若水哥:iOS 开发,手机屏幕尺寸和导航条高度)