1

I wondering why when I try to animate the path property of a CAShapeLayerwith a basic animation it works but when I try to do it with transaction it doesn't.

I've successfully animated other animatable properties using just transaction. Here is my current code:

    CATransaction.begin()
    CATransaction.setAnimationDuration(2.0)
        path = scalePath() // a scaled version of the original path
    CATransaction.commit()

the new path is obtained scaling the original path with this (very hardcoded) function inside an extension of CAShapeLayer:

func scalePath()->CGPath{
    var scaleTransform =  CGAffineTransform.identity.translatedBy(x: -150, y: -150)
    scaleTransform = scaleTransform.scaledBy(x: 10, y: 10)
    let newPath = path?.copy(using: &scaleTransform)

    return newPath!
}

Can you identify any issue?

4

1 回答 1

2

答案很简单,但有点不尽人意:虽然path属性是可动画的,但它不支持隐式动画。这在 path 属性的文档的讨论部分中被调用:

与大多数动画属性不同,path(与所有CGPathRef动画属性一样)不支持隐式动画。

显式与隐式动画

“显式”动画是通过调用层显式添加到层的动画对象(例如CABasicAnimation)。-addAnimation:forKey:

“隐式”动画是由于更改可动画属性而隐式发生的动画。

即使在事务中更改了属性,动画也被认为是隐式的。

于 2017-04-04T11:58:49.573 回答