gpt4 book ai didi

ios - 1.0 秒后 CAKeyframeAnimation 关键时间未执行

转载 作者:行者123 更新时间:2023-11-30 12:20:10 24 4
gpt4 key购买 nike

由于一些奇怪的原因,当我在 1 秒后输入关键时间时,它们似乎没有执行,但是当我将所有关键时间保留在 1 秒以下时,它们都正确执行。不知道为什么会发生这种情况,有人有什么想法吗?这是我正在使用的功能:

 func animateKeyFrameGroup() {

let opacity = CAKeyframeAnimation(keyPath: "opacity")
opacity.values = [1, 0, 1]
opacity.keyTimes = [0.1, 1.0, 1.5]

let translation = CAKeyframeAnimation(keyPath:"transform.translation")
translation.values = [CGPoint(x: 150, y: 300),CGPoint(x: 100, y: 100),CGPoint(x: 150, y: 300)]
translation.keyTimes = [0.1, 1.0, 1.5]

let cornerRadius = CAKeyframeAnimation(keyPath: "cornerRadius")
cornerRadius.values = [circle.bounds.width, circle.bounds.width/2, circle.bounds.width]
cornerRadius.keyTimes = [0.1, 1.0, 1.5]

let borderColor = CAKeyframeAnimation(keyPath: "borderColor")
borderColor.values = [UIColor.black.cgColor, UIColor.cyan.cgColor, UIColor.black.cgColor]
borderColor.keyTimes = [0.1, 1.0, 1.5]

let keyframeAnimationGroup = CAAnimationGroup()
keyframeAnimationGroup.animations = [translation, cornerRadius, borderColor, opacity]
keyframeAnimationGroup.duration = 2
keyframeAnimationGroup.isRemovedOnCompletion = false
keyframeAnimationGroup.fillMode = kCAFillModeForwards
circle.layer.add(keyframeAnimationGroup, forKey: nil)
}

最佳答案

根据Apple documentation :

Each value in the array is a floating point number between 0.0 and 1.0 that defines the time point (specified as a fraction of the animation’s total duration) at which to apply the corresponding keyframe value. Each successive value in the array must be greater than, or equal to, the previous value. Usually, the number of elements in the array should match the number of elements in the values property or the number of control points in the path property. If they do not, the timing of your animation might not be what you expect.

因此您可以更改总动画持续时间:keyframeAnimationGroup.duration = 2

和 keyTimes 是总持续时间的分数。例如:keyTime 等于 0.5 -> 2 * 0.5 = 1 秒,keyTime 等于 0.75 -> 2 * 0.75 = 1.5 秒,等等。

关于ios - 1.0 秒后 CAKeyframeAnimation 关键时间未执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44891384/

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