Tim Tim - 4 months ago 43
iOS Question

Capturing CATiledLayer content to another layer or image context

I'm trying to screen capture a view that uses CATiledLayers (for animation) but unable to get the image that I want.

I tried it on Apple's "PhotoScroller" sample application and added this:

CGContextRef ctx = UIGraphicsGetCurrentContext();
[self.view.layer renderInContext:ctx];
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();

However, the tiles don't render in the resulting UIImage and all I get is the tile outlines.

Seems that CATiledLayer's renderInContext behaves differently from CALayer.

Am I doing anything wrong in trying to capture the tiles? Is my only solution to render the tiles individually myself?

Tim Tim

In the end, rather than trying to render the tiles into another view just for animation, I just created a new instance of ImageScrollView, and animated the original one and the new one together before deallocating the original one.