【问题标题】:How can I slow down the CALayer.transform animation?如何减慢 CALayer.transform 动画的速度?
【发布时间】:2017-02-20 03:59:53
【问题描述】:

我目前必须在这些比例之间缩放一个层 (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 相同的速度制作动画。

任何关于如何完成这项工作的提示将不胜感激!

【问题讨论】:

    标签: ios animation transform duration


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-04
      • 1970-01-01
      • 2023-02-06
      • 2018-07-28
      • 1970-01-01
      • 2017-01-18
      • 1970-01-01
      • 2018-04-25
      相关资源
      最近更新 更多