I recently tried to capture a screenshot of a UIWebView with animated elements. The problem is that they appear in the screenshot at their original positions, for example, there was no animation. I tried using the following code to fix this problem:
CGRect screenRect = [[UIScreen mainScreen] bounds]; UIGraphicsBeginImageContext(self.frame.size); CGContextRef context = UIGraphicsGetCurrentContext(); [[UIColor clearColor] set]; CGContextFillRect(context, screenRect); [[self.layer presentationLayer] renderInContext:context]; UIImage *screenImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return screenImage;
But it disables my application using EXC_BAD_ACCESS. A little research showed that this behavior is explained by the fact that presentationLayer changes quickly; so when I try to render renderInContext it actually does not exist, and [self.layer presentationLayer] now returns another CALayer object.
So, the question is how to take an image from the current state of the animating layer, or (it can also be a solution), how to stop it from changing the presentation level for the duration of the screen capture?
[update] More interesting: presentationLayer seems to be empty, as it contains zero, as I see in the debugger ...
source share