iPhone X 上tabBar高度有时会变成49的问题
2018-05-24 本文已影响0人
uiari
首先我们来看下效果图

下面是设置代码

产生这种bug操作顺序是 vc->modal一个控制器->dismiss ->push一个控制器
解决办法:
1、我看了下美团的处理,如下图:

美团的是在push一个VC时保证tabBar的高度不变就行,如果测试不觉得是个bug,可以如此。
效果如图:

代码如下图:


首先自定义tabBarVC 在viewWillLayoutSubviews中设置tabBar的frame即可。
下面看下第二种解决办法!!!
2、使用navVC包tabBarVC
效果如图

代码如图:

注意的是:tabBarVC的子控制器不能用nav包住
3、自定义tabBar
@implementation HMTabBar
{
UIEdgeInsets _oldSafeAreaInsets;
}
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
_oldSafeAreaInsets = UIEdgeInsetsZero;
}
return self;
}
- (void)awakeFromNib {
[super awakeFromNib];
_oldSafeAreaInsets = UIEdgeInsetsZero;
}
- (void)safeAreaInsetsDidChange {
[super safeAreaInsetsDidChange];
if (!UIEdgeInsetsEqualToEdgeInsets(_oldSafeAreaInsets, self.safeAreaInsets)) {
[self invalidateIntrinsicContentSize];
if (self.superview) {
[self.superview setNeedsLayout];
[self.superview layoutSubviews];
}
}
}
- (CGSize)sizeThatFits:(CGSize)size {
size = [super sizeThatFits:size];
if (@available(iOS 11.0, *)) {
float bottomInset = self.safeAreaInsets.bottom;
if (bottomInset > 0 && size.height < 50 && (size.height + bottomInset < 90)) {
size.height += bottomInset;
}
}
return size;
}
- (void)setFrame:(CGRect)frame {
if (self.superview) {
if (frame.origin.y + frame.size.height != self.superview.frame.size.height) {
frame.origin.y = self.superview.frame.size.height - frame.size.height;
}
}
[super setFrame:frame];
}
@end
#import "HMTabBarVC.h"
#import "HMTabBar.h"
#define kTabBarHeight ([[UIApplication sharedApplication] statusBarFrame].size.height>20?83:49)
@interface HMTabBarVC ()
@end
@implementation HMTabBarVC
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
HMTabBar *tabBar = [[HMTabBar alloc] init];
[self setValue:tabBar forKey:@"tabBar"];
}
//- (void)viewWillAppear:(BOOL)animated {
// [super viewWillAppear:animated];
// [self.navigationController setNavigationBarHidden:YES animated:YES];
//}
//- (void)viewWillLayoutSubviews {
// [super viewWillLayoutSubviews];
//
// self.tabBar.frame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height - kTabBarHeight, [UIScreen mainScreen].bounds.size.width, kTabBarHeight);
//
//}
@end