ios - How to get the current animation step from a CAKeyframeAnimation -
i'm creating small button 2 different states. every state represented 2 cashapelayer
s , transition between states animated series of cakeyframeanimation
s/cabasicanimation
s, change path property of shape layers. question how animate state starting current animation (i.e. button pressed while animating).
normally, ask presentation layer current property value , use additive animation (as described here), since multi-step animation have figure out step animating , chain appropriate animation reverse previous state. rather tricky (i wanted have animation removeoncompletion=false
, query time offset of animations figure out animation active , how far).
unfortunately, setting layer speed 0.0 , animating timeoffset
, forth doesn't work either, since have secondary animations behave differently in opposite direction.
using custom layer property shape layers seems cumbersome, match progress property more current animation step.
so after trial , error come following "solution": use cadisplaylink
time update every frame , subtracting current timestamp timestamp when animation started, can figure out elapsed animation time, progress (by dividing through animationduration). way can start reverse animation offset. internally, calculate next frame keyframe animation , adjust keytimes new duration. can see implementation of here