How to calculate velocity for UIViewPropertyAnimator that gesture provides.

Updated
Jul 24, 2022 10:54 AM
Created
Dec 28, 2021 7:21 AM
Tags
SwiftiOSCoreAnimation
Attributes

image

Performs animations using a timing curve described by the motion of a spring. When dampingRatio is 1, the animation will smoothly decelerate to its final model values without oscillating. Damping ratios less than 1 will oscillate more and more before coming to a complete stop. You can use the initial spring velocity to specify how fast the object at the end of the simulated spring was moving before it was attached. It's a unit coordinate system, where 1 is defined as traveling the total animation distance in a second. So if you're changing an object's position by 200pt in this animation, and you want the animation to behave as if the object was moving at 100pt/s before the animation started, you'd pass 0.5. You'll typically want to pass 0 for the velocity. Velocity is specified as a vector for the convenience of animating position changes. For 1-dimensional properties the x-coordinate of the velocity vector is used.

moving 200pt and provides speed 100pt/s, passing 0.5

100pt / 200pt = 0.5

UIPanGesture’s velocity is expressed as pt per sec.

velocity / remaining distance = initial velocity