I'm adding several CALayers as sublayers of the layer of a UIView. The contents of each layer is a different image downloaded from a server. Each layer is animated from offscreen to a randomly generated position. The image data is downloaded asynchronously. Each image is approx 300x300 or smaller.
As a result of the random placement, the layers overlap and some are obscured by the layers above them. This is all good.
I'm removing layers as they become completely obscured from view using the suggestion in the answer to this question The calculations to determine coverage occur on a separate thread.
I have a UIPanGestureRecognizer that allows the user to drag the layers around on the screen.
I'm encountering a performance problem when the number of layers added approaches 25-30 and gets progressively worse. The animations become choppy and often are completely absent (the newly added layers simply appear in their final position). And the pan gestures are either ignored or result in choppy repositioning of the selected layer.
I'm supposing that I'm killing the GPU with all of the layers overlapping and another layer animating above?
Any suggestions on how to improve performance?
Best practices for dealing with large numbers of layers?
Is it better to have the layer begin animated in a separate view.layer than the previously added layers?
Thanks!