The target property’s rate of change at the start of a spring animation, enabling a smooth transition into the animation.
- iOS 10.0+
- Mac Catalyst 13.0+
- tvOS 10.0+
To create a smooth transition from an object in motion into a spring animation, initialize the spring timing parameters with an initial velocity. One common use of this property is to animate a view to a final resting position at the end of a pan gesture.
For view position animations, both components of the initial velocity vector are considered. Each component specifies the initial rate of change along the respective
y axes, normalized to the total distance of the animation. To calculate an initial velocity vector:
ydistance, in points, from the view’s current position to the final position.
dxcomponent of the initial velocity vector to the
xvelocity divided by the
xdistance. If the
dycomponent to the
yvelocity divided by the
ydistance. If the
The following example shows a function that performs this calculation using a velocity from the pan gesture recognizer and the view’s current and final positions.
The following example shows how a view controller can create a property animator with spring timing parameters. The view controller passes the result of
initial to the spring timing parameters’ initializer. In this example,
dragged is an outlet of the view controller. The value of
destination is the final resting position of
For other types of animations where the property value has a single dimension, such as a view’s
alpha, only the
dx component is considered.