Bandish Dave
Bandish Dave

Reputation: 811

Piechart animation completed event

CGFloat radius = 100;
CAShapeLayer *pieShape = [CAShapeLayer layer];
pieShape.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(100, 300, radius, radius)
                                           cornerRadius:radius].CGPath;

pieShape.fillColor   = [UIColor clearColor].CGColor;
pieShape.strokeColor = [UIColor orangeColor].CGColor;
pieShape.lineWidth   = 100;

CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
pathAnimation.duration = 15.0;
pathAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
pathAnimation.toValue = [NSNumber numberWithFloat:1.0f];
pathAnimation.removedOnCompletion = NO;
pathAnimation.fillMode = kCAFillModeForwards;
[pieShape addAnimation:pathAnimation forKey:@"strokeEndAnimation"];

Above code is working fine. But my problem is how can know that the duration 15 second is completed.

Upvotes: 0

Views: 47

Answers (1)

Max MacLeod
Max MacLeod

Reputation: 26662

You can tell the animation has completed using the superclass CAAnimation delegate method:

- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag

If the duration is specified as 15.0 seconds and the animationDidStop has been invoked with finished set to YES, the you know that the time has elapsed.

Upvotes: 1

Related Questions