表格中有WKWebView底部有空白问题及解决方案优缺点

32 篇文章 0 订阅
18 篇文章 0 订阅

表格中有WKWebView底部有空白。
理论上等网页加载完成,在didFinishNavigation修改表格高度,但是发现算出的高度比实际高出现底部空白。

-(void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigatio{
    
//    NSString *urlString =[webView.URL absoluteString];
//    self.model.contentHeight = webView.scrollView.contentSize.height;
//    if(self.model && [self.model isKindOfClass:[XQBQuestionDetailAnswerListUnitEntity class]] && self.model.contentHeight < webView.scrollView.contentSize.height && !self.model.isDidFinishNavigationMaxHeight)
//    {
//        if([PPSingleObject sharedInstance].isInQuestionDetailViewController)
//        {
//            self.model.isDidFinishNavigationMaxHeight = YES;
//            self.model.contentHeight = webView.scrollView.contentSize.height;
//            self.model.totalHeight = self.model.contentHeight + self.model.otherTotalHeight;
//            if(self.changeWebBlock && self.indexPath)
//            {
//                self.changeWebBlock(self.indexPath);
//            }
//        }
//    }
}

解决方案:kvo监控self.webView.scrollView的contentSize,延迟修正表格高度,只修正一次,防止循环刷页面。这样也存在不友好的问题,页面刷新两边产生闪烁,当有大图片或多个视频或图片时显示不完全。所以显示纯文本类的h5很有效,含单张不大的图片或含单个视频也可以。

   @weakify(self);
    [RACObserve(self.webView.scrollView, contentSize) subscribeNext:^(id x) {
        @strongify(self);
//        NSLog(@"xxxxxx:%@, nowTime:%lld毫秒 self.webView.scrollView.contentSize.height:%f,self.model.Body:%@", x, (long long)([[NSDate date] timeIntervalSince1970]*1000), self.webView.scrollView.contentSize.height,self.model.Body);
//        CGFloat contentHeight = self.webView.scrollView.contentSize.height;
        if(self.model && [self.model isKindOfClass:[XQBQuestionDetailAnswerListUnitEntity class]] && self.model.contentHeight < self.webView.scrollView.contentSize.height && !self.model.isMaxHeight && [PPSingleObject sharedInstance].isInQuestionDetailViewController && self.indexPath)
        {
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                @strongify(self);
                if(self.model && [self.model isKindOfClass:[XQBQuestionDetailAnswerListUnitEntity class]] && self.model.contentHeight < self.webView.scrollView.contentSize.height && !self.model.isMaxHeight && [PPSingleObject sharedInstance].isInQuestionDetailViewController && self.indexPath)
                {
                    bg_dispatch_main_async_safe(^{
                        @strongify(self);
                        if(self.model && [self.model isKindOfClass:[XQBQuestionDetailAnswerListUnitEntity class]] && self.model.contentHeight < self.webView.scrollView.contentSize.height && !self.model.isMaxHeight && [PPSingleObject sharedInstance].isInQuestionDetailViewController && self.indexPath)
                        {
                            self.model.isMaxHeight = YES;
                            self.model.contentHeight = self.webView.scrollView.contentSize.height;
                            self.model.totalHeight = self.model.contentHeight + self.model.otherTotalHeight;
                            if(self.changeWebBlock && self.indexPath)
                            {
                                self.changeWebBlock(self.indexPath);
                            }
                            
                        }
                        
                    });
                    
                }
            });
        }
    }];
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值