Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equation for time-versus-position graph for iOS 7 spring animation (animateWithDuration:delay:usingSpringWithDamping:...)

Given the spring parameters used in [UIView animateWithDuration:delay:usingSpringWithDamping:initialSpringVelocity:options:animations:completion:]:

  1. usingSpringWithDamping
  2. initialSpringVelocity

what is the mathematical equation for the time-versus-position graph?

(I'm trying to get a handle on the new spring animation API in iOS 7, but I'm not getting good results, and experimentation is taking too long. My goal is to get as close as possible to some animation curve that I would have specified using CAMediaTimingFunction if I were to use Core Animation instead of UIView's block-object animation.)

like image 764
ememem Avatar asked Dec 03 '13 11:12

ememem


1 Answers

DampingRatio

The damping ratio for the spring animation as it approaches its quiescent state.

To smoothly decelerate the animation without oscillation, use a value of 1. Employ a damping ratio closer to zero to increase oscillation.

As the damping value approaches 0.0 the spring becomes more bouncy.

Velocity

The initial spring velocity. For smooth start to the animation, match this value to the view’s velocity as it was prior to attachment.

A value of 1.0 for an initial spring velocity corresponds to the total animation distance traversed in one second. For example, if the total animation distance is 200 points and you want the start of the animation to match a view velocity of 100 pt/s, use a value of 0.5.

Example:

[UIView animateWithDuration:2.0
                      delay:0.0
     usingSpringWithDamping:0.4
      initialSpringVelocity:0.5
                    options:(UIViewAnimationOptions)options
                 animations:^{

                 }
                completion:nil];

enter image description here

like image 198
BootMaker Avatar answered Sep 30 '22 09:09

BootMaker