gpt4 book ai didi

ios - 具有交错开始时间的 CAKeyframeAnimation

转载 作者:行者123 更新时间:2023-11-28 19:26:43 26 4
gpt4 key购买 nike

我正在尝试创建一个动画,其中项目以交错的时间进入 View 。为此,我使用了 CAKeyframeAnimation,但为了实现惊人效果,我需要指定 beginTime

问题是我还希望动画在完成时不要快速返回到原始位置,所以我在模型上指定值如下:view.layer.transform = CATransform3DIdentity 动画被添加到图层之前。

但是,由于我已经指定了 beginTime,所以动画会快速回到初始位置。有解决办法吗?

func addAnimation(view: UIView, index: Int) {
let values = RK4SpringAnimation(tension: 600, friction: 60, initialVelocity: 0) // just provides an array of values between 0.0 and 1.0.
let positions = values.map { Float(view.layer.frame.width) - (Float($0) * Float(view.layer.frame.width)) }
let animation = CAKeyframeAnimation(keyPath: "transform.translation.x")
animation.values = positions
animation.duration = 0.716
animation.beginTime = CACurrentMediaTime() + Double(index) * 0.015
view.layer.transform = CATransform3DIdentity // set the final value on the model.
view.layer.add(animation, forKey: "transform2")
}

最佳答案

添加动画后,应将属性值设置为动画的最终值。最终值是 CATransform3DIdentity 吗?

如果动画的beginTime在未来,并且动画的开始值不等于它的结束值,那么你可以设置animation.fillMode = .backwards到告诉 Core Animation 将动画的开始值应用到层,直到达到 beginTime

func addAnimation(view: UIView, index: Int, show: Bool) {
let values = RK4SpringAnimation(tension: 600, friction: 60, initialVelocity: 0) // just provides an array of values between 0.0 and 1.0.
let positions = values.map { Float(view.layer.frame.width) - (Float($0) * Float(view.layer.frame.width)) }
let animation = CAKeyframeAnimation(keyPath: "transform.translation.x")
animation.values = positions
animation.duration = 0.716
animation.beginTime = CACurrentMediaTime() + Double(index) * 0.015
animation.fillMode = .backwards
view.layer.add(animation, forKey: animation.keyPath)
view.layer.setValue(positions.last!, forKey: animation.keyPath!)
}

关于ios - 具有交错开始时间的 CAKeyframeAnimation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53656246/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com