在UIVIew/CALayer动画期间回调

Cos*_*min 6 notifications animation calayer uiview ios

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

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

此外,我已经尝试过这篇文章的解决方案:核心动画进度回调,但它不起作用.

我希望drawInRect,或layoutSubviews,或类似的东西会被调用,但事实并非如此.

任何帮助,将不胜感激.

Vij*_*dar 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")
}
Run Code Online (Sandbox Code Playgroud)

我有 5 个点,并在每个点上传递动画层,我必须执行一些操作。