Search code examples
ioscocoa-touchuiwebviewuiscrollview

UIWebView contentInset without extra height at bottom


I'm creating a view controller that uses a web view which slides behind the navigation bar and status bar. To do this, I'm setting the webView.scrollView.contentInset property to have a top inset of 64.

However, this doesn't shrink the amount of area the web view wants to take up, so if a page is less than a screenful, it has 64 px of white space at the bottom to scroll through. The web views are in a vertical UIPageViewController, so this disrupts paging. Is there some way to get rid of this extra space?


Solution

  • I've sort of made an end-run around this problem by disabling scrolling on short pages. Basically, I use -stringByEvaluatingJavaScriptFromString: to run some JavaScript inside the page that walks down from document.body and computes the position of the bottom of the bottommost element. (document.body itself is always at least as large as the viewport, so I can't look at its size.) Then, back in Objective-C-land, I compare that to the height of the web view (less the inset), and if it's less, I disable scrolling. This is not a perfect solution, but it covers the worst symptoms.

    If someone can come up with a better solution than this, I'd love to hear about it! Either way, I can't award the bounty to myself, so someone will be getting it.