美文网首页
修复iPhone X设备tabBar高度乱跳的问题

修复iPhone X设备tabBar高度乱跳的问题

作者: SunnyLeong | 来源:发表于2018-12-17 12:03 被阅读265次
如图所示

如果控制器的hidesBottomBarWhenPushed属性设为true,进行push操作之后会出现tabBar高度错乱的现象,先变矮一截,然后返回的时候又弹回到正常高度,非常影响使用感受,这应该属于iOS 11在iPhone X设备下自身的bug。

解决一:
KVO监听tabBar的frame,当frame改变时,我们取一个高度最大的值重新布局tabBar就行了,

OC:

[self.tabBar addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionOld|NSKeyValueObservingOptionNew context:nil];

-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context{
    
    NSLog(@"KVO---%@----%@",change[@"old"],change[@"new"]);
    
    CGRect oldFrame = [change[@"old"] CGRectValue];
    CGRect newFrame = [change[@"new"] CGRectValue];
    
    if (oldFrame.size.height!= newFrame.size.height) {
        if (oldFrame.size.height>newFrame.size.height) {
            self.tabBar.frame=oldFrame;
        }else{
            self.tabBar.frame=newFrame;
        }
    }
}

解决二:

viewWillAppear中强制给 fram 赋值,kBottomSafeHeight判断是否 X 以上手机的34高度,这个方法没有上个好。

    CGRect frame = self.tabBarController.tabBar.frame;
    if (kBottomSafeHeight == 34.0) {
        frame.size = CGSizeMake(frame.size.width,83);
    }
    self.tabBarController.tabBar.frame = frame;

解决三:

loading...

相关文章

网友评论

      本文标题:修复iPhone X设备tabBar高度乱跳的问题

      本文链接:https://www.haomeiwen.com/subject/xapqkqtx.html