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

本文只做记录,就方便寻找

图片出自臭码农

主要解决问题:

需要解决的问题

解决方法:

重写 UINavigationController 类的 - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated 方法

具体代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
[super pushViewController:viewController animated:animated];
// 修正push控制器tabbar上移问题
if (@available(iOS 11.0, *)){
// 修改tabBra的frame
CGRect frame = self.tabBarController.tabBar.frame;
frame.origin.y = [UIScreen mainScreen].bounds.size.height - frame.size.height;
self.tabBarController.tabBar.frame = frame;
}
}