iphone - Stopping CAAnimation to add another CAAnimation -


i have rotating circle shape 5 subviews , animating changes fillcolor match subview on top. when have change color remove animations layer , add new 1 this:

[self.dynamiccolorcirclelayer removeallanimations]; //checked - doesn't matter if line added or not         switch (index) {             case 0: {                 cabasicanimation *fillcoloranimation = [cabasicanimation animationwithkeypath:@"fillcolor"];                 fillcoloranimation.duration = 2;                 //fillcoloranimation.fromvalue = (id)self.dynamiccolorcirclelayer.fillcolor;                 fillcoloranimation.tovalue = (id)[[uicolor redcolor] cgcolor];                 fillcoloranimation.removedoncompletion = no;                 fillcoloranimation.fillmode = kcafillmodeforwards;                 fillcoloranimation.delegate = self;                 [self.dynamiccolorcirclelayer addanimation:fillcoloranimation forkey:@"fillcolor"]; 

etc.

and delegate method:

- (void)animationdidstop:(caanimation *)theanimation finished:(bool)flag {     self.dynamiccolorcirclelayer.fillcolor = (__bridge cgcolorref)(((cabasicanimation*)theanimation).tovalue); } 

however when 1 animation hasn't ended , have start another, new 1 ends. fore example: animating color change red blue, i'm in middle of animation , have animate color change green. animation isn't showing, circle changes color green. if remove code animationdidstop(...), animation green, every animation start default (red) color.

what right way interrupt animation animation? also, possible make new animation start color had @ moment when removed older animation? (in example above, animating color change green color between red , blue)

refer question:

is there way pause cabasicanimation?

here first answer explains how pause existing animation , second answer says how stop same.

hope looking for.


Comments