logo
当前位置:首 页 > 移动开发 >ios > 查看文章

适配 iPhone X Push 过程中 TabBar 位置上移

ios, 移动开发 你是第3002个围观者 0条评论 供稿者: 标签:

前言

就在刚刚GitHub有同学给我提了个Issue,说我的框架在iPhone X上跑有bug,Push新页面的时候TabBar会上移。开玩笑吧?我的框架怎么会有bug,这一定是个误会,于是我去iPhone X跑了一下,哎哟嘿,脸好疼

image.png

发现问题

来个慢动作:

iPhone X 不完美.gif

上图可发现,点击跳转的时候,TabBar的确迅速上移了一段距离,没搞懂为啥,也许苹果别有用心,但我在心里还是骂了一下库克等人。

解决问题

在UINavigationController的基类重写pushViewController代理方法,在Push的时候修正一下TabBar的frame

– (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated

{

if (self.viewControllers.count > 0) {

if ([viewController conformsToProtocol:@protocol(XYTransitionProtocol)] && [self isNeedTransition:viewController]) {

viewController.hidesBottomBarWhenPushed = NO;

}else{

viewController.hidesBottomBarWhenPushed = YES;

}

 

}

[super pushViewController:viewController animated:animated];

// 修改tabBra的frame

CGRect frame = self.tabBarController.tabBar.frame;

frame.origin.y = [UIScreen mainScreen].bounds.size.height – frame.size.height;

self.tabBarController.tabBar.frame = frame;

}

修正完的效果:

iPhone X 完美.gif

我就说嘛,这一定是个误会,一个美丽的误会。

说说梦想,谈谈感悟 ,聊聊技术,有啥要说的来github留言吧 https://github.com/cjx2328

—— 陈 建鑫

陈建鑫
你可能也喜欢Related Posts
footer logo
未经许可请勿自行使用、转载、修改、复制、发行、出售、发表或以其它方式利用本网站之内容。站长联系:cjx2328#126.com(修改#为@)
Copyright ©ziao Studio All Rights Reserved. E-mail:cjx2328#126.com(#号改成@) 沪ICP备14052271号-3