I am looking for a way to get notified when the position of a view gets updated during the animation. I have checked different other posts on StackOverflow but none have the answer to my problem.
Adding myself as an observer to different properties such as frame, position, etc doesn't help - I only get called when I set the frame but not when the position animates.
Also I have tried the solution from this post: Core animation progress callback but it doesn't work as well.
I was hoping that drawInRect, or layoutSubviews, or something similar would get called, but it doesn't.
Any help would be appreciated.
You can add timer, and add timeInterval where you want any action.
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")
}
I have 5 dot and passing animation layer on each dot I have to do some action.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With