美文网首页
获取WKWebView内容高度(H5原生)

获取WKWebView内容高度(H5原生)

作者: 丘名山 | 来源:发表于2018-11-26 13:51 被阅读0次

wkwebView代理方法


- (void)webView:(WKWebView*)webView didFinishNavigation:(null_unspecifiedWKNavigation*)navigation{ [webView evaluateJavaScript:@"document.getElementById(\"testDiv\").offsetTop"completionHandler:^(id_Nullable result,NSError* _Nullable error) {//获取页面高度,并重置webview的frameCGFloatlastHeight = [result doubleValue]; webView.frame =CGRectMake(14,0, CurrentScreenWidth -28, lastHeight); webHeight = lastHeight; [self.tableView beginUpdates]; [self.tableView endUpdates]; }]; }


不管你的网页是什么样的,在尾部加一个div它的位置永远是你需要的高度.(一定要注意<meta content="width=device-width, initial-scale=1.0, maximum-scale=3.0, user-scalable=0;" name="viewport" />这段代码不加的话高度不准


相关文章

网友评论

      本文标题:获取WKWebView内容高度(H5原生)

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