【问题标题】:how to animation speed slow when animation stop动画停止时如何使动画速度变慢
【发布时间】:2018-05-08 05:48:33
【问题描述】:

我的代码如下。动画停止后如何减速?

extension UIView{
    func rotate() {
        let rotation : CABasicAnimation = CABasicAnimation(keyPath: "transform.rotation.z")
        rotation.fromValue = 0.0
        rotation.toValue = 25
        rotation.duration = 1.5
        rotation.isCumulative = true
        rotation.repeatCount = 1
        self.layer.add(rotation, forKey: "rotationAnimation")
    }
}

【问题讨论】:

  • 对慢动画使用完成块
  • 你可以继续降低 layer.speed。

标签: ios swift core-animation cabasicanimation


【解决方案1】:

请找到以下详细信息并在您的代码中添加以下行,

rotation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut)

EaseInOut 缓入缓出曲线导致动画开始 慢慢地,在持续时间的中间加速,然后慢慢地 在完成之前再次。这是大多数人的默认曲线 动画。

EaseIn 缓入曲线使动画开始缓慢,然后 随着进度的加快。

EaseOut 缓出曲线使动画快速开始,并且 然后在完成时放慢速度。

希望这对您有所帮助,如有任何疑问,请告诉我。

【讨论】:

    【解决方案2】:

    你可以使用self.layer.speed平滑地降低动画速度

    你可以这样做

    注意:这里你需要做一些修改它没有在xcode中测试

      let timer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { (timer) in
            self.layer.timeOffset = self.layer.convertTime(CACurrentMediaTime(), from: nil)
            if self.layer.speed == 0 { timer.invalidate() }
            self.layer.beginTime = CACurrentMediaTime()
            self.layer.speed -= 0.5
    
        }
        timer.fire()
    

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-18
      • 2012-01-25
      • 2015-10-18
      • 1970-01-01
      • 2013-10-04
      • 1970-01-01
      • 2011-10-19
      • 1970-01-01
      相关资源
      最近更新 更多