0

Hello I would like to know how to calculate height of a uiwebview with the content height is changing from time to time?

Therefore, it would change after webviewDidFinishLoad delegate method.

e.g. 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. It won't goes back to short one. Note that iOS safari could handle it without problem.

Ken Hui
  • 368
  • 3
  • 17

1 Answers1

0

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.

Joe Smith
  • 1,900
  • 1
  • 16
  • 15