title: How do I flatten CALayers
body: <p>I am rewriting an app that was using the core graphics library because it is extremely slow in iOS 4 and above. I am converting a lot of the code using the Core Animation library instead (specifically CALayer). The way I am doing it involves adding sublayers to a root layer. The problem is that it is a drawing program so it ends up with a lot of sublayers very quickly, and after about 20 it starts losing a lot of performance. I am trying to find a way to merge sublayers into one another or merge the sublayers into some background image. It would also be ideal if your suggestions minimized the use of the Core Graphics library (unless their performance wasn't impacted in iOS 4 and above). Any help or suggestions would be greatly appreciated. Thanks!</p>