ios - CAShapeLayer Animation without having to update the path -
when animating cashapelayer, necessary keep updating path of layer, or there way rely on cabasicanimation alone?
in example below, set 4 circles paths , draw them. want animate them down disappear. after animation has completed however, spring original paths.
int radius = halfwidth-30; //the radius distance out centre trackactive.path = [uibezierpath bezierpathwitharccenter:ciclecenter radius:radius startangle:degreestoradians(circlestart) endangle:degreestoradians(circleend) clockwise:true].cgpath; circleactive.path = [uibezierpath bezierpathwitharccenter:ciclecenter radius:radius startangle:degreestoradians(circlestart) endangle:degreestoradians(circleend) clockwise:true].cgpath; radius = halfwidth - 10; tracknew.path = [uibezierpath bezierpathwitharccenter:ciclecenter radius:radius startangle:degreestoradians(circlestart) endangle:degreestoradians(circleend) clockwise:true].cgpath; circlenew.path = [uibezierpath bezierpathwitharccenter:ciclecenter radius:radius startangle:degreestoradians(circlestart) endangle:degreestoradians(circleend) clockwise:true].cgpath; nsarray * layers = @[trackactive, circleactive, tracknew, circlenew]; (cashapelayer * layer in layers){ [catransaction begin]; cabasicanimation * animation = [cabasicanimation animationwithkeypath:@"strokeend"]; animation.duration = 1.0f; animation.removedoncompletion = false; animation.fromvalue = @(1.0); animation.tovalue = @(0.0); animation.timingfunction = [camediatimingfunction functionwithname:kcamediatimingfunctioneaseineaseout]; [layer addanimation:animation forkey:@"circleanimation"]; [catransaction commit]; }
i understand can add set new path:
[catransaction setcompletionblock:^{ //set new path layer.path = [uibezierpath bezierpathwitharccenter:ciclecenter radius:radius startangle:degreestoradians(circlestart) endangle:degreestoradians(arcend) clockwise:true].cgpath; }];
but prefer avoid keep having update path, , instead rely on animation layer exclusively. possible?
something like: layer.path = animation.path or animation.updatesoriginalpath=true; wishful thinking, not sure.
you can simplify code , omit spring effect:
[catransaction begin]; [catransaction setanimationduration:1.0]; [catransaction setanimationtimingfunction: kcamediatimingfunctioneaseineaseout]; layer.strokeend = 0.0; [catransaction commit];
the transaction create , add implicit animation object you.
Comments
Post a Comment