实测,必需要延迟一会儿才能获取正确高度。
-(void)webViewDidFinishLoad:(UIWebView *)webView {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
CGFloat height = 0.0;
[webView sizeToFit];
height = webView.scrollView.contentSize.height;
CGRect webFrame = webView.frame;
webFrame.size.height = height;
webView.frame = webFrame;
NSLog(@"网页的高度为=>%.f ", height);
});
}
网友评论