我正在使用动画旋转CAShapeLayer
,当我第一次激活动画时,它先以另一种方式旋转,然后进行动画处理。但是,当我再次为其设置动画时,它会按预期运行(旋转一次)。有人可以告诉我为什么会这样吗?
代码:
func rotateLayer() {
let rotate = CABasicAnimation(keyPath: "transform.rotation.z")
let degree = 300
let radian = CGFloat(degree) * .pi / 180
let result = CATransform3DMakeRotation(radian, 0, 0, 1)
rotate.toValue = radian
rotate.duration = 2.0
// animation.fillMode = kCAFillModeForwards
// animation.isRemovedOnCompletion = false
plus.add(rotate, forKey: rotate.keyPath)
plus.transform = result
}
示例: