Tim Tim - 1 year ago 83
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
Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download