UIVIew / CALayer动画期间的回调

问题描述 投票:6回答:1

我正在寻找一种在动画过程中更新视图位置时得到通知的方法。我在StackOverflow上检查了其他不同的帖子,但没有一个可以解决我的问题。

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

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

我希望可以调用drawInRect或layoutSubviews或类似的东西,但是没有。

任何帮助将不胜感激。

ios animation uiview notifications calayer
1个回答
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个点并通过动画层。

© www.soinside.com 2019 - 2024. All rights reserved.