Instance Method


Returns the animation object with the specified identifier.


func animation(forKey key: String) -> CAAnimation?



A string that specifies the identifier of the animation. This string corresponds to the identifier string you passed to the add(_:forKey:) method.

Return Value

The animation object matching the identifier, or nil if no such animation exists.


You can use this string to retrieve animation objects already associated with a layer. However, you must not modify any properties of the returned object. Doing so will result in undefined behavior.

See Also

Layer Animations

func add(CAAnimation, forKey: String?)

Add the specified animation object to the layer’s render tree.

func removeAllAnimations()

Remove all animations attached to the layer.

func removeAnimation(forKey: String)

Remove the animation object with the specified key.

func animationKeys() -> [String]?

Returns an array of strings that identify the animations currently attached to the layer.