简单的 CABasicAnimation,CAShapeLayer 用法示例.
-(void)initAnimationLayer
{
[self.hudLayer removeFromSuperlayer];
UIBezierPath *path=[UIBezierPath bezierPath];
float radius = self.bounds.size.width/2;
[path addArcWithCenter:CGPointMake(radius, radius) radius:radius startAngle:-2*M_PI endAngle:0 clockwise:NO];
self.hudLayer=[CAShapeLayer layer];
_hudLayer.path=path.CGPath;
_hudLayer.fillColor=[UIColor colorWithWhite:0 alpha:0.5].CGColor;
_hudLayer.strokeColor=[UIColor colorWithWhite:1 alpha:0.7].CGColor;
_hudLayer.lineWidth= MAX(5, radius/10);
_hudLayer.lineCap = @"round";
_hudLayer.bounds = self.bounds;
_hudLayer.anchorPoint = CGPointMake(0.5, 0.5);
_hudLayer.position = CGPointMake(radius, radius);
_hudLayer.strokeStart = 1;
[self.layer addSublayer:_hudLayer];
}
-(void)startAnimation
{
[self initAnimationLayer];
CABasicAnimation *anim=[CABasicAnimation animationWithKeyPath:@"strokeStart"];
anim.duration=0.5;
anim.fromValue=@(1);
anim.toValue=@(0.9);
anim.delegate = self;
[_hudLayer addAnimation:anim forKey:nil];
_hudLayer.strokeStart = 0.9;
_hudLayer.strokeEnd = 1;
}
-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
CABasicAnimation *rotation=[CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotation.duration=1;
rotation.fromValue=@(0);
rotation.toValue=@(M_PI*2);
rotation.repeatCount = INT_MAX;
[_hudLayer addAnimation:rotation forKey:nil];
}
文件: http://download.csdn.net/detail/li6185377/6030763