iOS 动画 -- Chapter 2

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)
图1
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)
图2

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)
图3
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

图4比图3中的登录按钮弹跳速度更快,更久停下来,而且初始时的幅度更大。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容