繁体   English   中英

UIVIew/CALayer 动画期间的回调

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM