Ios CAShapeLayer,使用事务设置路径动画
我想知道为什么当我试图用一个基本的动画来设置Ios CAShapeLayer,使用事务设置路径动画,ios,core-animation,calayer,cgpath,ios-animations,Ios,Core Animation,Calayer,Cgpath,Ios Animations,我想知道为什么当我试图用一个基本的动画来设置CAShapeLayer的path属性的动画时,它能工作,但当我试图用事务来做时,它却不能 我已经成功地使用just transaction为其他可设置动画的属性设置了动画。这是我目前的代码: CATransaction.begin() CATransaction.setAnimationDuration(2.0) path = scalePath() // a scaled version of the origina
CAShapeLayer
的path
属性的动画时,它能工作,但当我试图用事务来做时,它却不能
我已经成功地使用just transaction为其他可设置动画的属性设置了动画。这是我目前的代码:
CATransaction.begin()
CATransaction.setAnimationDuration(2.0)
path = scalePath() // a scaled version of the original path
CATransaction.commit()
新路径是通过在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!
}
你能找出任何问题吗 答案很简单,但有点不令人满意:虽然路径
属性是可设置动画的,但它不支持隐式动画。这在以下章节的讨论部分进行了阐述:
与大多数可设置动画的属性不同,path
(与所有CGPathRef
可设置动画的属性一样)不支持隐式动画
显式与隐式动画
“显式”动画是通过调用层上的-addAnimation:forKey:
显式添加到层中的动画对象(例如cabasicanition
)
“隐式”动画是由于更改可设置动画的属性而隐式发生的动画
即使在事务中更改了属性,动画也被认为是隐式的