How can I tell when a UIWebView has finished drawing to a context?

Posted by phopkins on Stack Overflow See other posts from Stack Overflow or by phopkins
Published on 2010-05-10T03:57:22Z Indexed on 2010/05/10 4:08 UTC
Read the original article Hit count: 507

In my code I'm trying to show a UIWebView as a page is loading, and then, when it's done, capture an image from the web view to cache and display later (so I don't have to reload and render the web page).

I have something along the lines of:

CGContextRef context = CGBitmapContextCreate(…);
[[webView layer] renderInContext:context];

CGImageRef imageRef = CGBitmapContextCreateImage(context);
UIImage *image = [UIImage imageWithCGImage:imageRef];

The problem I'm running into is that, due to UIWebView's tiling, sometimes only half of the page is rendered to the context by the time I capture the image.

Is there a way to detect or block on UIWebView's background rendering thread so that I can get the image only after all of the rendering has finished?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about uiwebview