objective c - CABasicAnimation stop animation on completion - iOS -


i have ios app using cabasicanimation on repeat:

    cabasicanimation *fadeanim = [cabasicanimation animationwithkeypath:@"opacity"];     fadeanim.fromvalue = [nsnumber numberwithfloat:1.0];     fadeanim.tovalue = [nsnumber numberwithfloat:0.2];     fadeanim.duration = 1.0;     fadeanim.autoreverses = yes;     fadeanim.repeatcount = infinity;     [colourbutton.titlelabel.layer addanimation:fadeanim forkey:@"opacity"]; 

i have button when pressed meant stop animation.

-(ibaction)stopanim {     [colourbutton.titlelabel.layer removeallanimations]; } 

it works fine 1 thing noticing is stops animation suddenly, doesn't let animation finish. how can finish current animation , stop. (or in other words how can removeallanimations....withanimation?).

on side note, need include coreanimation framework work. far animation running , havn't imported coreanimation framework.

thanks, dan.

just add animation , after remove first 1 this:

    cabasicanimation *endanimation = [cabasicanimation animationwithkeypath:@"opacity"];     endanimation.fromvalue = @(((calayer *)colourbutton.titlelabel.layer.presentationlayer).opacity);     endanimation.tovalue = @(1);     endanimation.duration = 1.0;     [colourbutton.titlelabel.layer addanimation:endanimation forkey:@"end"];     [colourbutton.titlelabel.layer removeanimationforkey:@"opacity"]; 

the key here use presentation layer current state. don't forget set actual end state of layer, because animation removed on completion.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -