我将分解最终为我解决这个问题的原因。
我不得不将我的内容包装在其中。
<html><head><meta name=\"viewport\" content=\"initial-scale=1, user-scalable=no, width=device-width\" /></head><body>%@</body></html>
执行以下视图确实加载。
-(void)webViewDidFinishLoad:(UIWebView *)webView {
[self layoutSubviews];
webView.scrollView.scrollEnabled = NO; // Property available in iOS 5.0 and later
CGRect frame = webView.frame;
frame.size.height = 1; // Set the height to a small one.
webView.frame = frame; // Set webView's Frame, forcing the Layout of its embedded scrollView with current Frame's constraints (Width set above).
frame.size.height = webView.scrollView.contentSize.height; // Get the corresponding height from the webView's embedded scrollView.
webView.frame = frame;
}
和
-(void) layoutSubviews {
[super layoutSubviews];
[body stringByEvaluatingJavaScriptFromString:
[NSString stringWithFormat:
@"document.querySelector('meta[name=viewport]').setAttribute('content', 'width=%d;', false); ",
(int)body.frame.size.width]];
}
最后,我的 webview 做了所有正确的事情来适应内容。