简体   繁体   English

用动态内容计算UIWebView的高度

[英]Calculate UIWebView height with dynamic content

Hello I would like to know how to calculate height of a uiwebview with the content height is changing from time to time? 您好我想知道如何计算uiwebview的高度,其中内容高度会不时变化?

Therefore, it would change after webviewDidFinishLoad delegate method. 因此,它将在webviewDidFinishLoad委托方法之后发生变化。

eg like this one 例如像这样

"<!DOCTYPE html><html><head><script src=\"https://code.jquery.com/jquery-2.1.1.min.js\"></script><meta charset=\"utf-8\"><title>JS Bin</title></head><body><h1>Heading</h1><div></div><h2>Body</h2><p>Attention he extremity unwilling on otherwise. Conviction up partiality as delightful is discovered. Yet jennings resolved disposed exertion you off. Left did fond drew fat head poor. So if he into shot half many long. China fully him every fat was world grave.</p> <p>Excited him now natural saw passage offices you minuter. At by asked being court hopes. Farther so friends am to detract. Forbade concern do private be. Offending residence but men engrossed shy. Pretend am earnest offered arrived company so on. Felicity informed yet had admitted strictly how you. Luckily friends do ashamed to do suppose. Tried meant mr smile so. Exquisite behaviour as to middleton perfectly. Chicken no wishing waiting am. Say concerns dwelling graceful six humoured. Whether mr up savings talking an. Active mutual nor father mother exeter change six did all. It prepare is ye nothing blushes up brought. Or as gravity pasture limited evening on. Wicket around beauty say she. Frankness resembled say not new smallness you discovery. Noisier ferrars yet shyness weather ten colonel. Too him himself engaged husband pursuit musical. Man age but him determine consisted therefore. Dinner to beyond regret wished an branch he. Remain bed but expect suffer little repair. </p><p>Attention he extremity unwilling on otherwise. Conviction up partiality as delightful is discovered. Yet jennings resolved disposed exertion you off. Left did fond drew fat head poor. So if he into shot half many long. China fully him every fat was world grave.</p><p>Attention he extremity unwilling on otherwise. Conviction up partiality as delightful is discovered. Yet jennings resolved disposed exertion you off. Left did fond drew fat head poor. So if he into shot half many long. China fully him every fat was world grave.</p> <h3>Footer</h3><script>$(function() {var count = 0;$(document.body).click(function() {var test = count%2 === 0;$('div').css('background', test ? '#AAA' : '#888').height(test ? 150 : 300);count++;}).click();setInterval(function() {$(document.body).click();}, 1500);});</script></body></html>"

Thanks 谢谢

UPDATE 更新

I tried KVO, the contentSize.height only changed to longer one. 我尝试了KVO,contentSize.height仅更改为更长的一个。 It won't goes back to short one. 它不会回到空头。 Note that iOS safari could handle it without problem. 请注意,iOS野生动物园可以毫无问题地处理它。

It is unlikely you can estimate the size before the content is loaded. 您不太可能在加载内容之前估算大小。 However, you can set the web view size based on the content size after the content is loaded in the delegate call webViewDidFinishLoad. 但是,在将内容加载到委托调用webViewDidFinishLoad中后,可以根据内容大小设置Web视图大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM