CAKeyframeAnimation 关键时间在 1.0 秒后未执行

CAKeyframeAnimation key times after 1.0 sec not executing

出于某种奇怪的原因,当我在 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 秒,等等