Capture image from presentation.layer view.layer

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 ...

+4
source share
1 answer

Ok, the problem was in CSS:

 -webkit-transform: perspective(100px) translate3d(200px, 100px, -50px) rotateY(15deg); 

Any perspective or rotateY / rotateX kills the position of the element in the screenshot taken from view.layer renderInContext. Thus, there is no way to capture β€œtruly 3D” positioned elements on a web page.

0
source

Source: https://habr.com/ru/post/1432567/


All Articles