我怎样才能减慢 CALayer.transform 动画的速度?

How can I slow down the CALayer.transform animation?

我目前必须在这些比例之间缩放的图层 (CALayer) 才能创建动画。

private let invisibleScale = CATransform3DMakeScale(0.0,0.0,1.0)
private let fullScale = CATransform3DMakeScale(2.5,2.5,1.0)

只需在我的图层上调用以下函数,图层就会按照我想要的方式进行动画处理(除了有点快)。

animationLayer.transform = invisibleScale
animationLayer.transform = fullScale

我尝试添加 CABasicAnimation 并将转换作为值,但这不起作用,因为它在完成动画后返回到原始比例。像这样:

let animation = CABasicAnimation(keyPath: "transform")
animation.toValue = NSValue(caTransform3D: invisibleScale)
animation.duration = animationDuration
animationLayer.add(animation, forKey: "transform")

所以我尝试在最后添加 animationLayer.transform = fullScale 来更新动画后的状态。

let animation = CABasicAnimation(keyPath: "transform")
animation.toValue = NSValue(caTransform3D: invisibleScale)
animation.duration = animationDuration
animationLayer.add(animation, forKey: "transform")
animationLayer.transform = fullScale

这会产生一个看起来与调用完全一样的动画:

animationLayer.transform = fullScale

我也尝试过类似的东西:

UIView.animate(withDuration: 10) {
        self.animationLayer.transform = fullScale
}

这也以与键入 animationLayer.transform = invisibleScale.

相同的速度生成动画

任何关于如何使这项工作有效的提示都将不胜感激!

我终于找到了使用 CATransaction 的解决方案!

CATransaction.begin()
CATransaction.setAnimationDuration(0.5)
animationLayer.transform = transform
CATransaction.commit()