问题: 在iPhone X 以后机型切换Push VC过程中,Tabbar会先上移一下,不知道苹果怎么搞的,iPhone X系列适配真是坑爹啊,不,是坑儿子。 O(∩_∩)O哈哈~
慢动作图看下效果:
解决办法:
重写这个- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
方法,重新设置下Tabbar 的frame:
/**
* 重写这个方法,能拦截所有的push操作
*/
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
if (self.viewControllers.count > 0) {
viewController.hidesBottomBarWhenPushed = YES;
}
[super pushViewController:viewController animated:animated];
// 修改tabBra的frame iPhone X切换切面tabbar上移bug修复
CGRect frame = self.tabBarController.tabBar.frame;
frame.origin.y = [UIScreen mainScreen].bounds.size.height - frame.size.height;
self.tabBarController.tabBar.frame = frame;
}
修复后效果:
tips:判断iPhone X系列手机方法:
NS_INLINE BOOL isIPhoneXSeries() {
BOOL iPhoneXSeries = NO;
if (UIDevice.currentDevice.userInterfaceIdiom != UIUserInterfaceIdiomPhone) {
return iPhoneXSeries;
}
if (@available(iOS 11.0, *)) {
UIWindow *mainWindow = [[[UIApplication sharedApplication] delegate] window];
if (mainWindow.safeAreaInsets.bottom > 0.0) {
iPhoneXSeries = YES;
}
}
return iPhoneXSeries;
}