熟悉 Web 前端的同學(xué)想必已經(jīng)見(jiàn)識(shí)了瀏覽器中通過(guò) easing functions 來(lái)實(shí)現(xiàn)格式的動(dòng)畫的方式了,比如這個(gè)項(xiàng)目 tweenjs,它封裝了一些 easing functions 并提供了一些簡(jiǎn)潔的 APIs。
最近需要在 iOS 中使用 easing functions,于是從 Robert Penner's Easing Functions 那里摘取了各式的 easing functions 并封裝成了簡(jiǎn)單的 API 已在 iOS 中使用。
方法的簽名:
static func animate(from: Double, to: Double, duration: Double,
tween: TweenFunction, setter: MCDAnimatorValueSetter) -> MCDAnimator
使用示例:
let animatorX = MCDAnimator.animate(Double(v.center.x), to: Double(x), duration: 1, tween: TweenBounceEaseOut)
{ (newValue) in
var c = self.v.center
c.x = CGFloat(newValue)
self.v.center = c
}
animatorX.start()
演示:
源碼已經(jīng)托管在 MCDAnimator
如果你想知道每個(gè) easing function 的具體效果的話,可以看看這 Demo