前言
就在刚刚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
我就说嘛,这一定是个误会,一个美丽的误会。