很多时候需要先计算出webview的内容高度再去自适应高度,其实我们可以等UIWebViewDelegate的方法走完更新一下约束即可
//#pragma mark - UIWebViewDelegate
- (void)webViewDidFinishLoad:(UIWebView *)aWebView {
CGRect frame = aWebView.frame;
frame.size.height = 1;
aWebView.frame = frame;
CGFloat yHeight = [[aWebView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight"] floatValue];
frame.size.height = yHeight;
aWebView.frame = frame;
//更新webVeiw的约束
_webViewHeightConstraint.constant = yHeight;
}