简体   繁体   中英

Callback during UIVIew/CALayer animation

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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