About Spring Animation
Spring Animation is essentially a special animated curve that has been widely used in system animations since IOS 7. The self-contained animations shown in are actually using Spring Animation:
In fact, almost all system animations from IOS 7 use Spring Animation, including App folder open/close effects, keyboard pop-up effects, switch effects for uiswitch controls, Push animations between different View controllers, Modal Animations that appear and disappear, the appearance and disappearance of Siri, and so on. A comparison of the motion curves for Spring Animation and normal animations:
To be more intuitive, I've made a demo project that lists the animated effects of Spring Animation, Ease-out Animation and Linear Animation, respectively, from left to right:
Can be seen, and the system comes with the ease-out effect compared to the Spring Animation earlier speed increased faster, in the animation time certain premise, give people feel faster and cleaner.
Api
Starting with IOS 8, Apple exposes the Spring Animation API, and developers can create such animations with simple code:
+ (void)animatewithduration:(nstimeinterval) duration delay:(nstimeinterval) delay usingspringwithdampinginitialspringvelocityoptionsanimations:(void (^) (void)) Completion:(void (^) (finished))completion
The method is UIView
the class method.
The Spring Animation API has two more parameters than normal animations, respectively usingSpringWithDamping
initialSpringVelocity
.
Dumping ratio
usingSpringWithDamping
The range is 0.0f
to 1.0f
, the smaller the value of the "Spring" vibration effect is more obvious. Demonstrated in the initialSpringVelocity
case 0.0f
of the circumstances, usingSpringWithDamping
respectively taken 0.2f
, 0.5f
and 1.0f
the case.
Initial velocity
initialSpringVelocity
Indicates the initial speed, the higher the number, the faster the movement begins. Illustrates the usingSpringWithDamping
1.0f
case when, initialSpringVelocity
respectively, take 5.0f
, 15.0f
and 25.0f
. It is worth noting that the initial speed value is higher and the time is short, there will also be rebound situation.
Use
Spring Animation is an ideal alternative to linear or ease-out animations. Because the IOS itself is heavily used by Spring Animation, users are accustomed to the animated effect, so using it can make the App feel more natural, in Apple's words is "instantly familiar". In addition, Spring Animation is not only available for locations, it applies to all properties that can be animated.
IOS 8 Spring Animation