Tension and Friction to UIView animation damping, duration and velocity

#1

Hey there!
Principle provides Spring Animations using Tension and Friction, while iOS uses Duration, Damping and Initial Velocity. I’m wondering if you could provide guidance on how to convert these values provided by our design team.

image

Thank you :slight_smile:
Shai.

1 Like

#2

I’m curious about this too, great question, hope someone can help you out. Following the thread for answers.

0 Likes

#3

The iOS API that uses duration is discouraged. The duration parameter is a hack that the original Apple engineer who made it regrets adding - it essentially takes the duration and tries to work backwards from that to figure out tension and friction - there isn’t always a solution to this equation and it gets very problematic when the layer could possibly animate from different positions (say after a drag ends).

There is an iOS Spring API that doesn’t take a duration. Use that.

1 Like

#4

The real solution here was found yesterday - using UISpringTimingParamaters:

https://developer.apple.com/documentation/uikit/uispringtimingparameters

Where stiffness correlates to tension and damping correlates to friction.

You should feed this to a UIViewPropertyAnimator: https://developer.apple.com/documentation/uikit/uiviewpropertyanimator/1648362-init

The duration is ignored when using the spring parameters initializer.

2 Likes

closed #5

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.

0 Likes