Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/98.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios CAShapeLayer,使用事务设置路径动画_Ios_Core Animation_Calayer_Cgpath_Ios Animations - Fatal编程技术网

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

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

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