iPhone X 简直就是神一般的存在

iPhone X的分辨率是:1125 X 2436
但是iPhone X的 UIScreen bounds 却是:CGRectMake(0, 0, 375, 812)

#define isIphoneX   CGRectEqualToRect([UIScreen mainScreen].bounds, CGRectMake(0, 0, 375, 812))

其次是tabbar高度,在iPhone 4,5,6,7,8(plus略过)上tabbar的高度是49 ,在iPhone X 上也是49 ,不是83吗 ?? ,我们写一个包含tabbar的项目在iPhone X 上运行看下 。。

上面我们提到 iPhone X的tabbar高度是49,但是底部无效点击区域的高度是33 ,所以有点地方也说iPhone X的tabbar高度是 82 ,为什么说下面高度33 的区域是无效点击区域了 ?? 来张gif

那么这个就比较尴尬了 。。。。 虽然在iPhone X上 微信和 app store都是这个样子 ,底部有无效的区域;但是总有个别另类把无效区域变成有效区域 先来张图。。。

某宝的APP , 我们不能说某宝的APP始作俑者,但是对于展示类的APP来说屏幕区域展示多多益善,展示类APP巴不得全屏展示 。。。 或许这种展示类的APP的产品经理看到iPhone X 的淘宝 ,然后对程序猿说:跟淘宝一样,不用我说程序猿肯定脸一黑 我朝APP市场不就是 一直在模仿从未被超越吗 ?? 如何能做到跟淘宝一样了 ?? 首先我们需要把系统的tabbar搞出来,这是第一步

1.构造系统的tabbar


#import "ViewController.h"
#import "H1ViewController.h"
#import "H2ViewController.h"
#import "H3ViewController.h"
#import "H4ViewController.h"#define isIphoneX   CGRectEqualToRect([UIScreen mainScreen].bounds, CGRectMake(0, 0, 375, 812))@interface ViewController (){UITabBarController *viewController;
}@end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];H1ViewController *h1 = [[H1ViewController alloc] init];h1.tabBarItem.image = [UIImage imageNamed:@"1"];h1.tabBarItem.title = @"首页";UINavigationController *h11 = [[UINavigationController alloc] initWithRootViewController:h1];H2ViewController *h2 = [[H2ViewController alloc] init];h2.tabBarItem.image = [UIImage imageNamed:@"2"];h2.tabBarItem.title = @"联系人";UINavigationController *h22 = [[UINavigationController alloc] initWithRootViewController:h2];H3ViewController *h3 = [[H3ViewController alloc] init];h3.tabBarItem.image = [UIImage imageNamed:@"3"];h3.tabBarItem.title = @"消息";UINavigationController *h33 = [[UINavigationController alloc] initWithRootViewController:h3];H4ViewController *h4 = [[H4ViewController alloc] init];h4.tabBarItem.image = [UIImage imageNamed:@"4"];h4.tabBarItem.title = @"设置";UINavigationController *h44 = [[UINavigationController alloc] initWithRootViewController:h4];[[UITabBar appearance] setTintColor:[UIColor colorWithRed:255 / 255.0 green:50 / 255.0 blue:50 / 255.0 alpha:1.0]];UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 49)];backView.backgroundColor = [UIColor cyanColor];UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage new]];imageView.contentMode = UIViewContentModeScaleToFill;imageView.frame = backView.frame;[backView addSubview:imageView];viewController = [[UITabBarController alloc] init];viewController.viewControllers = @[h11, h22, h33, h44];viewController.view.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);[viewController.tabBar setClipsToBounds:YES];[viewController.tabBar insertSubview:backView atIndex:0];viewController.tabBar.opaque = YES;[self.view addSubview:viewController.view];NSLog(@"%@",NSStringFromCGRect(viewController.tabBar.frame));
}

运行代码将得到 以下界面

问题来了 。。。。。 tabbar如何让它下去了 ???也就是我们需要改变tabbar的高度或坐标 ,相信很多人都改过。。。发现无效,tabbar还是那个tabbar了。。 如何改了 ??

我们需要自定义UITabBarController
.h文件

#import <UIKit/UIKit.h>@interface HBTabBarController : UITabBarController
@end

.m文件


#import "HBTabBarController.h"#define isIphoneX   CGRectEqualToRect([UIScreen mainScreen].bounds, CGRectMake(0, 0, 375, 812))@interface HBTabBarController ()@end@implementation HBTabBarController- (void)viewDidLoad {[super viewDidLoad];// Do any additional setup after loading the view.
}
-(void)viewWillLayoutSubviews{[super viewWillLayoutSubviews];if (isIphoneX) {CGRect frame = self.tabBar.frame;frame.size.height = 49;frame.origin.y = self.view.frame.size.height - frame.size.height;self.tabBar.frame = frame;for (UITabBarItem *item in self.tabBar.items) {item.imageInsets = UIEdgeInsetsMake(15,0, -15, 0);[item setTitlePositionAdjustment:UIOffsetMake(0, 32)];}}
}- (void)didReceiveMemoryWarning {[super didReceiveMemoryWarning];// Dispose of any resources that can be recreated.
}

同样我们需要修改下 ViewController.m ,直接上代码

#import "ViewController.h"
#import "H1ViewController.h"
#import "H2ViewController.h"
#import "H3ViewController.h"
#import "H4ViewController.h"#import "HBTabBarController.h"//#define isIphoneX   CGRectEqualToRect([UIScreen mainScreen].bounds, CGRectMake(0, 0, 375, 812))@interface ViewController (){HBTabBarController *viewController;
}@end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];H1ViewController *h1 = [[H1ViewController alloc] init];h1.tabBarItem.image = [UIImage imageNamed:@"1"];h1.tabBarItem.title = @"首页";UINavigationController *h11 = [[UINavigationController alloc] initWithRootViewController:h1];H2ViewController *h2 = [[H2ViewController alloc] init];h2.tabBarItem.image = [UIImage imageNamed:@"2"];h2.tabBarItem.title = @"联系人";UINavigationController *h22 = [[UINavigationController alloc] initWithRootViewController:h2];H3ViewController *h3 = [[H3ViewController alloc] init];h3.tabBarItem.image = [UIImage imageNamed:@"3"];h3.tabBarItem.title = @"消息";UINavigationController *h33 = [[UINavigationController alloc] initWithRootViewController:h3];H4ViewController *h4 = [[H4ViewController alloc] init];h4.tabBarItem.image = [UIImage imageNamed:@"4"];h4.tabBarItem.title = @"设置";UINavigationController *h44 = [[UINavigationController alloc] initWithRootViewController:h4];[[UITabBar appearance] setTintColor:[UIColor colorWithRed:255 / 255.0 green:50 / 255.0 blue:50 / 255.0 alpha:1.0]];UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 49)];backView.backgroundColor = [UIColor cyanColor];UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage new]];imageView.contentMode = UIViewContentModeScaleToFill;imageView.frame = backView.frame;[backView addSubview:imageView];viewController = [[HBTabBarController alloc] init];viewController.viewControllers = @[h11, h22, h33, h44];viewController.view.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);[viewController.tabBar setClipsToBounds:YES];[viewController.tabBar insertSubview:backView atIndex:0];viewController.tabBar.opaque = YES;[self.view addSubview:viewController.view];NSLog(@"%@",NSStringFromCGRect(viewController.tabBar.frame));
}

我们把UITabBarController替换成我们自定义的HBTabBarController ,我们运行看下效果

看起来是成功了。 。。。 但是 。。。 我们点击看一看 。。

很麻烦,单击Tabbar下面的文本根本无法触发Tabbar切换 。。。。。 貌似我们点击的都是无效区域。。。。这个比较麻烦 。。。。。 那么我们怎么解决了 ? 我们知道,这种情况(Tabbar下移动,点击无法切换)只会在iPhone X上出现 ,那么在iPhone X 我们所谓的无效区域 touches 是否执行了 ?? 我们来看下

无效区域 touches 执行了 ! 那这个就好办了 。。。。

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{if (!isIphoneX) {return;}NSSet *allTouches = [event allTouches];    //返回与当前接收者有关的所有的触摸对象UITouch *touch = [allTouches anyObject];   //视图中的所有对象UIView *v =  [touch view];if (!CGRectEqualToRect(v.frame, CGRectMake(0, 0, 375, 49))) {return;}CGPoint point = [touch locationInView:v]; //返回触摸点在视图中的当前坐标int x = point.x;int y = point.y;if (y>49||y<0) {return;}CGFloat w = 375.0/4;if (x>=0&&x<=w) {viewController.selectedIndex = 0;}else if (x>w&&x<=w*2){viewController.selectedIndex = 1;}else if (x>w*2&&x<=w*3){viewController.selectedIndex = 2;}else if (x>w*3&&x<=w*4){viewController.selectedIndex = 3;}NSLog(@"touch (x, y) is (%d, %d) %@", x, y,[touch view] );
}

貌似大功告成 ,但是 。。。 有个地方有点蛋疼 。。。。

蛋疼。。 其实系统提供了去掉的方法。。。。。

-(BOOL)prefersHomeIndicatorAutoHidden{return YES;
}

那么iPhone X上面的 Tabbar 基本 介绍完了 。。。 代码下载地址
http://download.csdn.net/download/chmod_r_755/10119241

iPhone X UITabBarController UITabBar 适配解读相关推荐

  1. iOS11、iPhone X、Xcode9 适配指南

    2017.09.23 不断完善中... 2017.10.02 新增 iPhone X 适配官方中文文档 更新iOS11后,发现有些地方需要做适配,整理后按照优先级分为以下三类: 单纯升级iOS11后造 ...

  2. html刘海屏高度,iphone刘海屏网页适配方法

    1. 下面是实现iphonex 刘海屏前端网页适配的一个插值算法小案例 Title body, ul { margin: 0; } ul { padding-left: 10px; } li { li ...

  3. iPhone屏幕大小和适配建议(包括 XR XS XSM )

    //4 ----:{{0, 0}, {320, 480}} //5.5s ----:{{0, 0}, {320, 568}} //6.6s.7.8 ----:{{0, 0}, {375, 667}} ...

  4. 快速弄懂iPhone X 设计尺寸和适配

    iPhone X适配分析 被iPhone X刷了一天屏,到下午实在受不了各种假帖.标题写着"iPhone X 适配.指南.设计稿" 内容却是发布会回顾和手机介绍.索性自己去官网找素 ...

  5. iPhone X全屏适配

    当你的项目运行于iPhone X模拟器的时候是否会出现以下这种情况??不能全屏,,上下出现了大黑边,,受到以前在设置了启动页,,把启动页删除出现的上下黑框的启发,,于是想到只要给给iPhone X设置 ...

  6. iPhone6 和 iPhone 6 plus的适配

    苹果每出一款产品,都会引起广大IOS程序员们的深深关注!是不是又该做适配了?是不是又该学习新东西了?种种的担心挂在心头. 下面我谈谈我对iPhone6 和 iPhone 6 plus适配问题的理解: ...

  7. 苹果x css适配,CSS如何适配iPhone全面屏 CSS适配iPhone全面屏方法

    本篇文章小编给大家分享一下CSS适配iPhone全面屏方法,通过文中代码详细介绍了适配方法,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看. 一.media query方式 / ...

  8. android小米刘海屏幕适配,Android、iPhone手机刘海屏适配判断

    一.简介 手机屏幕的正上方居中位置(下图黑色区域)会被挖掉一个孔,屏幕被挖掉的区域无法正常显示内容,这种类型的屏幕就是刘海屏,也有其他叫法:挖孔屏.凹凸屏等等 二.Android刘海屏适配判断 1.判 ...

  9. iPhone 12 启动图适配 (黑屏问题,已解)

    Xcode 昨天发布了12.1 版本.里面有了iPhone 12 系列模拟器. 跑了一下之前的项目,启动图(LaucnScreen)是黑屏. 分别百度和谷歌了一下 iPhone 12 适配,均没有相关 ...

最新文章

  1. 单点登陆_别再问我单点登陆
  2. css继承和边框圆角 及 写三角形
  3. 学习能力和工作态度是准绳
  4. Spring MVC : 概念模型 HandlerMethod(转载)
  5. mplab x ide 中文使用手册_中文文档:MPLAB ICD 4在线调试器用户指南
  6. 数字化转型方法论_双中台:企业数字化转型的核心战略与方法论
  7. DOM学习之路--Mr.Ember
  8. 强化学习-下棋系列 - 01 五子棋
  9. 阶乘浅析poj1150 3406 zoj1222 2358
  10. c# MessageBox 用法大全
  11. No query specified
  12. 蒂姆•库克在斯坦福毕业典礼上都讲了啥?
  13. 小米note3android8.0,小米Note3 lineage16 安卓9.0 极致省电 纯净 完美root Xposed 经典版...
  14. 编写程序实现通过有道或百度翻译url对用户输入数据进行翻译_8亿用户AI有道:超强神经网络翻译技术大解密...
  15. hadoop配置文件workers
  16. 安全性设计之-ip白名单设计
  17. javascript怎么隐藏显示div
  18. mysql 外键有啥用途_外键
  19. 微信股票行情助手-微云助手发布微信群股票行情播报机器人助手
  20. loadrunner(三)

热门文章

  1. 2016年,都有哪些企业进入了美国的储能业务“角斗场”
  2. 数据库系统概论实验三——创建及管理数据表
  3. 11. 将学生的学号及平均成绩定义为一个视图(s_g),学号用sno表示,平均成绩用gavg表示。
  4. 2023年1月12日,openKylin 0.9.5正式发布!
  5. Calendar 日历
  6. Nine Knights
  7. 数据结构 第一章 数据结构绪论
  8. 讯景rx560D战狼版896流处理器,镁光显存开核失败抢救方法
  9. COCO格式数据集制作并使用yolact网络训练
  10. 大数据晋级之路(5)Hadoop,Spark,Storm综合比较