ios - Stop spinning image in place, using CABasicAnimation -
i have uiimageview
spinning using following code:
cabasicanimation *rotation; rotation = [cabasicanimation animationwithkeypath:@"transform.rotation"]; rotation.fromvalue = [nsnumber numberwithfloat:0]; rotation.tovalue = [nsnumber numberwithfloat:(2*m_pi)]; rotation.duration = 2.0; rotation.repeatcount = huge_valf; [myview.layer addanimation:rotation forkey:@"spin"];
and can stop running
[myview.layer removeanimationforkey:@"spin"];
however, when animation stops, image resets started. looks little awkward if image mid-turn, stop in rotation. assume require getting current rotation amount before stopping animation, , setting rotation amount instantly after stopping animation. not know how though.
there couple ways of doing this. 1 way affecting layers speed property can find example of in answer post: is there way pause cabasicanimation?. way more of means pause animation.
since want stop it, recommend keep calling removeanimationforkey: are, , coupling catransform3d made match view's presentationlayer's transform before stopped animating. give try:
catransform3d mytransform = [(calayer*)[myview.layer presentationlayer] transform]; [myview.layer removeanimationforkey:@"spin"]; [myview.layer settransform:mytransform];
Comments
Post a Comment