How to store CALayers for reuse?

I have a bunch of identical CALayers that I want to reuse. Often, some of them must disappear, and then use them again in a different position within the same super layer (half a second later).

What is the best way (in terms of performance) to keep them until they disappear from the screen? setHidden: YES or setOpacity: 0 or removeFromSuperLayer? Or something else I don’t think about?

(There are about 12 identical round CALayers with content from UIImage and about 30 CAShapeLayers, each of which has only a line segment, although usually in different orientations -)

+3
source share
2 answers

You must use nsset or nsarray to maintain a queue of unused calories. This process will be similar to what you do when using table elements.

As each calendaring agent removes FromSuperLayer'd, put it in your collection and remove it from the collection when you need it.

0
source

The three examples you mentioned all seem reasonable. You really need to check each of them and see what gives your application the best performance, the results may surprise you.

0
source

Source: https://habr.com/ru/post/1769725/


All Articles