簡體   English   中英

動畫停止時如何動畫速度慢

[英]how to animation speed slow when animation stop

我的代碼如下。 動畫停止后如何加快速度?

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")
    }
}

請查看以下詳細信息並在代碼中添加以下行,

rotation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut)

EaseInOut Easy -in緩出曲線使動畫緩慢開始,在其持續時間的中間加速,然后在完成之前再次減速。 這是大多數動畫的默認曲線。

EaseIn緩入曲線使動畫開始緩慢,然后隨着進展而加速。

EaseOut緩出曲線會使動畫快速開始,然后在完成時減慢速度。

希望這對您有所幫助,如果有任何疑問,請告訴我。

您可以使用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()

希望它有所幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM