ios - CABasicAnimation + UIBezierPath -
i'm trying create circular bar such 1 can find around recording button in native camera on ios when doing timelapse.
a circle created along animation, , once completed removed again "naturally".
i tried next code:
cashapelayer *circle = [cashapelayer layer]; circle.path = [uibezierpath bezierpathwitharccenter:cgpointmake(self.lapsebtnoutlet.center.x, self.lapsebtnoutlet.center.y) radius:28 startangle:2*m_pi*0-m_pi_2 endangle:2*m_pi*1-m_pi_2 clockwise:yes].cgpath; circle.fillcolor = [uicolor clearcolor].cgcolor; circle.strokecolor = [uicolor whitecolor].cgcolor; circle.linewidth = 2.0; cabasicanimation *animation = [cabasicanimation animationwithkeypath:@"strokeend"]; animation.duration = self.lapseinterval; animation.removedoncompletion = no; animation.fromvalue = @(0); animation.tovalue = @(1); animation.timingfunction = [camediatimingfunction functionwithname:kcamediatimingfunctionlinear]; [circle addanimation:animation forkey:@"drawcircleanimation"];
but problem don't know how "remove" line start-to-end.
i tried autoreverse property, removes circle end-to-start instead start-to-end. ideas?
you need animate strokestart
0 1, , when animation finishes, remove shape layer.
- (void)viewdidload { [super viewdidload]; [self performselector:@selector(animateproperty:) withobject:@"strokeend" afterdelay:1]; [self performselector:@selector(animateproperty:) withobject:@"strokestart" afterdelay:3]; } -(void)animateproperty:(nsstring *) prop { if (! self.circle) { self.circle = [cashapelayer layer]; self.circle.path = [uibezierpath bezierpathwitharccenter:cgpointmake(self.lapsebtnoutlet.center.x, self.lapsebtnoutlet.center.y) radius:28 startangle:2*m_pi*0-m_pi_2 endangle:2*m_pi*1-m_pi_2 clockwise:yes].cgpath; self.circle.fillcolor = [uicolor clearcolor].cgcolor; self.circle.strokecolor = [uicolor whitecolor].cgcolor; self.circle.linewidth = 2.0; [self.view.layer addsublayer:self.circle]; } cabasicanimation *animation = [cabasicanimation animationwithkeypath:prop]; animation.delegate = ([prop isequaltostring:@"strokestart"])? self : nil; animation.duration = 1; animation.removedoncompletion = no; animation.fromvalue = @0; animation.tovalue = @1; [self.circle addanimation:animation forkey:prop]; } -(void)animationdidstop:(caanimation *)anim finished:(bool)flag { [self.circle removefromsuperlayer]; self.circle = nil; }
Comments
Post a Comment