I wonder what's the importance of the key when adding CABasicAnimation to a layer.
I have several views visible at the same time. To each I apply a function so that it is animated. In summary this function does a lot of things and ends up with:
layer.add(animation, forKey: "jiggle")
As the animation is called on each view, should it have a different key or whatever?
The doc says:
Only one animation per unique key is added to the layer.
But it doesn't say if it should be unique to the entire application.
The key is per layer. The whole idea is you can't have more than one animation with the same key on any given layer. The key allows you to remove the animation from the layer using
CALayer removeAnimation(forKey:)or to retrieve the animation withanimation(forKey:).The full comment on the
keyparameter ofCALayer add(animation:forKey:)states:Note the mention of
kCATransitionandnil. If the key wasn't per layer then only one layer in the entire app (or even system) could benilor usekCATransition.Think of it like a dictionary where each layer has its own dictionary. Two different layers have two different dictionaries so there's no worry about key conflicts between the two.