views:

98

answers:

1

How can I create/prepare a CALayer offscreen, so that when the page is displayed, then all it has to do is to display the prepared layer?

+2  A: 

Render your content into an CGBitmapContext, pull a CGImageRef off of that and set that as the contents of the CALayer. Take a look at Creating a Bitmap Graphics Context for example code for most of this.

But if your real problem is that your drawInContext: is too slow, you should first look at breaking that up so that you pre-calculate everything when the data changes and only do drawing in drawInContext:. This is generally the better approach. Don't pre-render the layer itself; pre-calculate everything you need to render the layer quickly. But for very complicated drawing, the CGImageRef approach is useful.

Rob Napier