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"];
以上代码工作正常。 但我的问题是如何知道持续时间15秒完成。
答案 0 :(得分:1)
您可以使用超类CAAnimation
委托方法告知动画已完成:
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag
如果持续时间指定为15.0秒,并且animationDidStop
已设置为finished
,则会调用YES
,您知道时间已过。