How can I callback as a CABasicAnimation is animat

2019-03-05 15:40发布

问题:

I have an animation I'm using to snap a rotatable UIView to a circular grid. As the view animates, I need to update another view based on the rotating views position.

How can I go about getting the position of the rotating view as it animates into position?

回答1:

When animation starts you can start a function that will be polling current view position using a timer (I suppose you will need to get presentationLayer from view's layer and get position values from it).

There's no callbacks for CAAnimation other than animationDidStart and animationDidStop so it seems that's the solution (if I'm not mistaken it was also mentioned so in one of WWDC videos).