由于項目需要试浙,需要動態(tài)加載網頁高度姿鸿,在網上找了很多方法都不是很理想,比如說:
-(void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
{
//? document.body.offsetHeight? document.body.scrollHeight? document.getElementById(\"content\").offsetHeight;
[webView evaluateJavaScript:@"document.body.offsetHeight" completionHandler:^(id _Nullable result, NSError * _Nullable error) {
//獲取頁面高度珊燎,并重置webview的frame
CGFloat documentHeight = [result doubleValue];
CGRect frame = webView.frame;
frame.size.height = documentHeight;
webView.frame = frame;
height = frame.size.height;
mainScrollview.contentSize = CGSizeMake(0, height);
NSLog(@"webheight\\\\\\\\%f? ? %f? %f",frame.size.height ,_DescriHeaderView.frame.size.height,mainScrollview.contentSize.height);
}];
}
網絡上大多說的都是以上的方法矮瘟,可是我的并項目中并不好用,于是發(fā)現了下面的方法饭望,一下子就解決了仗哨。
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
NSLog(@"11111");
CGRect frame = webViewkk.frame;
frame.size.height = webViewkk.scrollView.contentSize.height;
webViewkk.frame = frame;
mainScrollview.contentSize = CGSizeMake(MainScreenWidth, MaxY(webViewkk));
}
分享給大家,希望對你有幫助铅辞。