[英]Callback during UIVIew/CALayer animation
我正在尋找一種在動畫期間視圖位置更新時獲得通知的方法。 我在 StackOverflow 上檢查過其他不同的帖子,但沒有一個能解決我的問題。
將自己作為觀察者添加到不同的屬性(例如框架、位置等)並沒有幫助 - 我只在設置框架時被調用,而在位置動畫時不會被調用。
我也嘗試了這篇文章中的解決方案: 核心動畫進度回調,但效果不佳。
我希望 drawInRect 或 layoutSubviews 或類似的東西會被調用,但事實並非如此。
任何幫助,將不勝感激。
您可以添加計時器,並在您想要任何操作的地方添加 timeInterval。
let animation = CABasicAnimation(keyPath: "strokeEnd")
animation.delegate = self
animation.fromValue = 0
animation.duration = 3
shapeLayer.add(animation, forKey: "MyAnimation")
// save shape layer
self.shapeLayer = shapeLayer
timer.invalidate() // just in case this button is tapped multiple times
// start the timer
timer = Timer.scheduledTimer(timeInterval: 3/5, target: self, selector: #selector(timerAction), userInfo: nil, repeats: true)
@objc func timerAction() {
print("done")
}
我有 5 個點並在每個點上傳遞動畫層我必須做一些動作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.