How can you make an NSArray full of multiple instances of a CALayer (all with the same frame, contents etc)?
Background: CALayer takes a bit of overhead to create, so I would like to create a number of CALayers (all sharing the same properties) in the init method of a class (to be used later on in that class.)
In the Layers panel of the source image, select the layer that you want to copy. Do one of the following: Choose Select > All to select all of the pixels in the layer, and choose Edit > Copy. Then make the destination image active, and choose Edit > Paste.
Select the layer from the [Layer] palette you want to duplicate. Select the [Layer] menu > [Duplicate Layer] to duplicate it.
An object that manages image-based content and allows you to perform animations on that content.
CALayer doesn't have a built in -(id)copy
method. I'm not sure why. It's not difficult to gin up your own however. Create a CALayer category and write your own copy method. All you have to do is instantiate and manually get the public ivars/properties from the original and set to the new copy. Don't forget to call [super copy]
BTW, CALayer is an object. You can add it to an NSArray.
I haven't tried this with CALayer
specifically, but I know you can perform a deep-copy by taking advantage of NSCoding
:
CALayer *layer = [NSKeyedUnarchiver unarchiveObjectWithData:[NSKeyedArchiver archivedDataWithRootObject:layer]];
I'm not sure how copying them would really help with performance, though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With