UsingSpringWithDamping
值位于0.0 到 1.0 之间,越小越会有弹跳效果。为1.0时,几乎没有弹跳效果。
UIView.animate(withDuration: 3, delay: 0.5, usingSpringWithDamping: 0.1, initialSpringVelocity: 0.0, options: [], animations: {
self.loginButton.center.y -= 50
self.loginButton.alpha = 1
}, completion: nil)
UIView.animate(withDuration: 3, delay: 0.5, usingSpringWithDamping: 1, initialSpringVelocity: 0.0, options: [], animations: {
self.loginButton.center.y -= 50
self.loginButton.alpha = 1
}, completion: nil)
UsingSpringWithDamping:该阻尼值影响所有属性的动画效果,因此图1中的透明度也有弹跳变化。
initialSpringVelocity
数值越大,动画的开始速度越快,也就需要更长的时间才能停下。
UIView.animate(withDuration: 3, delay: 0.5, usingSpringWithDamping: 0.1, initialSpringVelocity: 1, options: [], animations: {
self.loginButton.center.y -= 50
self.loginButton.alpha = 1
}, completion: nil)
UIView.animate(withDuration: 3, delay: 0.5, usingSpringWithDamping: 0.1, initialSpringVelocity: 100, options: [], animations: {
self.loginButton.center.y -= 50
self.loginButton.alpha = 1
}, completion: nil)
图4比图3中的登录按钮弹跳速度更快,更久停下来,而且初始时的幅度更大。