ios - Why when I set a low duration value for my CABasicAnimation does it jump? -


sample project: http://cl.ly/1w3v3b0d2001

i'm using cabasicanimation create progress indicator pie chart. similar ios 7 app download animation:

enter image description here

the animation set follows:

- (void)drawrect:(cgrect)rect {     [super drawrect:rect];      cgfloat radius = cgrectgetwidth(self.frame) / 2;     cgfloat inset  = 1;     cashapelayer *ring = [cashapelayer layer];     ring.path = [uibezierpath bezierpathwithroundedrect:cgrectinset(self.bounds, inset, inset)                                            cornerradius:radius-inset].cgpath;      ring.fillcolor = [uicolor clearcolor].cgcolor;     ring.strokecolor = [uicolor whitecolor].cgcolor;     ring.linewidth = 2;      self.innerpie = [cashapelayer layer];     inset = radius/2;     self.innerpie.path = [uibezierpath bezierpathwithroundedrect:cgrectinset(self.bounds, inset, inset)                                                cornerradius:radius-inset].cgpath;     self.innerpie.fillcolor = [uicolor clearcolor].cgcolor;     self.innerpie.strokecolor = [uicolor whitecolor].cgcolor;     self.innerpie.linewidth = (radius-inset)*2;      self.innerpie.strokestart = 0;     self.innerpie.strokeend = 0;      [self.layer addsublayer:ring];     [self.layer addsublayer:self.innerpie];      self.progress = 0.0; } 

the animation triggered setting progress of view:

- (void)setprogress:(cgfloat)progress animated:(bool)animated {     self.progress = progress;      if (animated) {         cgfloat totaldurationforfullcircleanimation = 0.25;          cabasicanimation *pathanimation = [cabasicanimation animationwithkeypath:@"strokeend"];         self.innerpie.strokeend = progress;         pathanimation.delegate = self;         pathanimation.fromvalue = @([self.innerpie.presentationlayer strokeend]);         pathanimation.tovalue = @(progress);         pathanimation.duration = totaldurationforfullcircleanimation * ([pathanimation.tovalue floatvalue] - [pathanimation.fromvalue floatvalue]);          [self.innerpie addanimation:pathanimation forkey:@"strokeendanimation"];     }     else {         [catransaction setdisableactions:yes];         [catransaction begin];         self.innerpie.strokeend = progress;         [catransaction commit];     } } 

however, in cases set progress small, such 0.25, there's jump in animation. goes little forward clockwise, jumps back, keeps going forward normal. it's worth nothing this not happen if duration or progress set higher.

how stop jump? code works in every case except when progress low. doing wrong?

ah! should have seen earlier. problem line in if (animated) block:

self.innerpie.strokeend = progress; 

since innerpie core animation layer, causes implicit animation (most property changes do). animation fighting own animation. can prevent happening disabling implicit animation while setting strokeend:

[catransaction begin]; [catransaction setdisableactions:yes]; self.innerpie.strokeend = progress; [catransaction commit]; 

(note how setdisableactions: within begin/commit.)

alternatively, can remove own animation , use automatic one, using setanimationduration: change length.

original suggestions:

my guess drawrect: being called, resets strokeend value. layers should not set in drawrect: anyway. try moving setup init method or didmovetowindow: or similar.

if that's not effective, suggest adding log statements track value of progress , [self.innerpie.presentationlayer strokeend] each time method called; perhaps they're not doing expect.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -