【发布时间】: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