【问题标题】:CAShapeLayer, animating path with TransactionsCAShapeLayer,用事务动画化路径
【发布时间】:2017-08-22 02:29:25
【问题描述】:

我想知道为什么当我尝试使用基本动画为CAShapeLayerpath 属性设置动画时,它可以工作,但是当我尝试使用事务时却不行。

我已经成功地使用事务为其他animatable 属性设置了动画。这是我当前的代码:

    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!
}

您能找出任何问题吗?

【问题讨论】:

    标签: ios core-animation calayer cgpath ios-animations


    【解决方案1】:

    答案很简单,但有点不尽人意:虽然path 属性是可动画的,但它不支持隐式 动画。这是在the documentation for the path property 的讨论部分中提到的:

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

    显式与隐式动画

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多