UIWebView 不会调整大小以适应内容?
我的 webView 在完成加载后无法正确调整大小。我已经尝试过这段代码。
- (void)webViewDidFinishLoad:(UIWebView *)webview {
CGRect frame = webView.frame;
frame.size.height = 1;
frame.size.width = screenWidth;
webView.frame = frame;
CGSize fittingSize = [webView sizeThatFits:CGSizeZero];
frame.size = fittingSize;
webView.frame = frame;
[bodyScroll setContentSize:CGSizeMake(screenWidth, webView.frame.origin.y + webView.frame.size.height+keyboardRectY+60)];
它增加了超出 screenWidth 的宽度,因此我的内容水平扩展超出了我不想要的视图大小。
改变
CGSize fittingSize = [webView sizeThatFits:CGSizeMake(screenWidht, 1)];
也会导致同样的情况。
我怎样才能摆脱这个? webview 宽度应始终保持为屏幕宽度,只有其高度应根据内容大小进行调整,以便 webview 几乎适合整个内容。
提前致谢
My webView is not resizing properly after it finished loading. I have tried this code.
- (void)webViewDidFinishLoad:(UIWebView *)webview {
CGRect frame = webView.frame;
frame.size.height = 1;
frame.size.width = screenWidth;
webView.frame = frame;
CGSize fittingSize = [webView sizeThatFits:CGSizeZero];
frame.size = fittingSize;
webView.frame = frame;
[bodyScroll setContentSize:CGSizeMake(screenWidth, webView.frame.origin.y + webView.frame.size.height+keyboardRectY+60)];
It is incresing the width beyond the screenWidth and hence my content horizontally expands beyond the view size which I don't want.
changing
CGSize fittingSize = [webView sizeThatFits:CGSizeMake(screenWidht, 1)];
also leads to the same situation.
How can I get rid of this? The webview width should always remain as screenwidth and only it's height should adjust based on the content size so that the webView just about fits the whole content.
Thanks in Advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
设置
frame
的大小时,您将覆盖之前设置的宽度。这应该是:When setting the size of
frame
, you are overwriting the width you set previously. This should it: