使用动态内容计算UIWebView高度

时间:2015-05-30 17:37:15

标签: html ios uiwebview uiwebviewdelegate

您好我想知道如何计算uiwebview的高度,内容高度会不时变化?

因此,它会在webviewDidFinishLoad委托方法之后发生变化。

e.g。喜欢这个

"<!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>"

由于

更新

我试过KVO,contentSize.height只改为更长的一个。它不会回到短暂的。请注意,iOS safari可以毫无问题地处理它。

1 个答案:

答案 0 :(得分:0)

在加载内容之前,您不太可能估计大小。但是,您可以在委托调用webViewDidFinishLoad中加载内容后,根据内容大小设置Web视图大小。