在UIVIew / CALayer动画期间回调

时间:2014-05-13 13:39:19

标签: ios animation uiview notifications calayer

我正在寻找一种在动画期间更新视图位置时获得通知的方法。我已经在StackOverflow上检查了不同的其他帖子,但没有一个能解决我的问题。

将自己作为观察者添加到不同的属性(如帧,位置等)也无济于事 - 我只在设置帧时调用,而不是在位置设置动画时调用。

此外,我也尝试过这篇文章中的解决方案:Core animation progress callback但它也不起作用。

我希望调用drawInRect,layoutSubviews或类似的东西,但它不会被调用。

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:1)

您可以添加计时器,并在需要执行任何操作的位置添加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个点并在每个点上传递动画层,我必须做一些动作。