簡體   English   中英

CAShapeLayer,使用事務動畫路徑

[英]CAShapeLayer, animating path with Transactions

我想知道為什么當我嘗試使用基本動畫為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!
}

您能找出任何問題嗎?

答案很簡單,但有點不令人滿意:雖然path屬性是可動畫的,但它不支持隱式動畫。 在path的文檔的“討論”部分中對此進行了標注

與大多數可設置動畫的屬性不同, path (與所有CGPathRef可設置動畫的屬性一樣)不支持隱式動畫。

顯式動畫與隱式動畫

“顯式”動畫是通過在圖層上調用-addAnimation:forKey: 顯式添加到圖層的動畫對象(例如CABasicAnimation )。

“隱式”動畫是由於更改可設置動畫的屬性而隱式發生的動畫。

即使在事務中更改了屬性,動畫也被認為是隱式的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM