Animator represents a dynamic animator for a particular variable. It continuously moves some value towards its target. You can use this to animate a layer property in a physical fashion.

You would normally access an animator through Layer.animators (see LayerAnimatorStore), like this:

myLayer.animators.x.target = 20 // Animate x to 20
// Here, myLayer.animators.x is the Animator.

Dynamic animations are distinct from more traditional animations in that you don’t specify a duration or a curve: motion depends on the layer’s velocity and its distance from the target. Instead, you adjust a more abstract speed parameter (see springSpeed below).

Method reference

  • public func stop() this.stop()

    Immediately stops the dynamic animation. You might use this when the user touches a moving layer.

  • Variables

  • public var target: Target?this.target(Varies, see below)

    The target value for this animator. The Animator will continuously move its layer’s value closer to this value. When the animation completes, the target value will be set back to nilundefined.

    The type of this property will vary based on the animator. For instance, Layer.animators.x’s target is a DoubleNumber, but Layer.animators.backgroundColor is a Color.

  • public var springSpeed: Doublethis.springSpeedNumber

    How quickly the animation resolves to the target value. Valid range from 0 to 20. Defaults to 4.

  • public var springBounciness: Double = 12.0 this.springBouncinessNumber

    How springily the animation resolves to the target value. Valid range from 0 to 20. Defaults to 12.

  • public var velocity: Target?this.velocity(Varies, see below)

    The instantaneous velocity of the layer, specified in target’s units per second.

    For instance, if this animator affects x, velocity is specified in points per second.

  • public var completionHandler: (() -> Void)? this.completionHandlerFunction

    This function is called whenever the animation resolves to its target value.