2

This problem is best explained with a screenshot or three!

Somehow, I have a UIWebView that is not rendering its content fully...or is it? I can certainly tap on and select the text in the webView, even if I can't see it! What is going on here?

WebView With Invisible Text

To be clear, this only happens sometimes when I'm displaying content in a webView. It's random, not easily reproducible.

I have a UIPageViewController, with each "page" viewController having a UIWebView in it. To populate with content I inject HTML, and when webViewDidFinishLoading: returns I run a JS function that does some mangling and finishes the population. (Mangling done in JS for cross-platform-ability.)

The way it's set up, you can tap on a link in the HTML and a new page is created in the PageViewController, which is then animated to, and fresh content is loaded into this new page. Think "dictionary app".

But as I say, randomly I get this phenomenon, where the content is definitely there and touchable, but not visible.

Here are some more revealing screenshots:

Reveal First Look

Reveal Explosion

You can see that the UIWebView, flattened, looks to Reveal just the same as the iPad device screenshot. But if I go into the tree and explode the UIWebBrowserView (content view for the UIScrollView that's in the UIWebView) you can see the whole HTML page!

I'm not familiar enough with the inner workings of drawing views to be able to isolate this issue and solve it, so I would appreciate any help.

P.S. One potentially related thing is that I called setViewControllers:animated: on my UIPageViewController, which creates the new UIWebView and starts the loading process, and then in the completion: block of that call, I call it again but without animation, to trick the UIPageViewController into getting "lost" and forcing it to re-query the datasource next time the user attempts to pan. See this post for details. Anyway, might not be relevant, but had to mention it.

Community
  • 1
  • 1
Matt Mc
  • 8,882
  • 6
  • 53
  • 89
  • My idea is that the web view had some kind of intelligent code that only renders the HTML for whats on screen (perhaps it only does this in low memory situations since it effects scrolling experience?). So the issue might be that it thinks the frame is smaller than it actually is. Perhaps it has a small frame with `clipsToBounds` set to NO. Can you post any code related to setting frames, bounds and `clipsToBounds` of the view and the web-view? – Robert Aug 02 '13 at 16:58
  • Did you investigate if it might be a timing issue? I've seen bugs like this disappear when adding delays here and there. I wouldn't then use delays as a fix for anything, but it may help track down the source of the issue (e.g. that "PS" with the "trick" part sounds suspicious) – mvds Aug 05 '13 at 22:25
  • What happens if you dont run your JS in webViewDidFinishLoad? Do you see the same problem happening? – TomSwift Aug 05 '13 at 22:43
  • Have you solved this issue? – brush51 Jul 21 '15 at 16:15
  • @brush51 Somehow I did get around this. I don't recall ever finding out what was causing it, but I think that I approached the problem from a different angle, perhaps reworking my architecture and the way I was loading the webview concurrently to other things. Sorry I can't be more help. – Matt Mc Jul 28 '15 at 20:52

1 Answers1

1

You need 2 things:

  • to have correct layout, (Autolayout since iOS 6.0)
  • it's needed to put UIWebView on scrollview and than set scrollview size in webview delegate (after HTML rendering is finished)
galuszkak
  • 513
  • 4
  • 25
Leszek Zarna
  • 3,253
  • 26
  • 26