代码比较简单,就不多加赘述,核心代码如下:
UIBezierPath *maskFinalBP= [UIBezierPath bezierPathWithOvalInRect:CGRectInset(self.maskView.frame, 0, 0)];
self.maskView.backgroundColor = [UIColor redColor];
NSInteger itemWidth = self.maskView.bounds.size.width/2;
UIBezierPath *maskStartBP = [UIBezierPath bezierPathWithOvalInRect:CGRectInset(self.maskView.frame, itemWidth, itemWidth)];
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.path = maskStartBP.CGPath;
self.maskView.layer.mask = maskLayer;
CABasicAnimation *maskLayerAnimation = [CABasicAnimation animationWithKeyPath:@"path"];
maskLayerAnimation.fromValue =(__bridge id)((maskStartBP.CGPath)) ;
maskLayerAnimation.toValue = (__bridge id)(maskFinalBP.CGPath);
maskLayerAnimation.removedOnCompletion = NO;
// 时间
maskLayerAnimation.duration = 5.f;
maskLayerAnimation.delegate = self;
[maskLayer addAnimation:maskLayerAnimation forKey:@"path"];
github地址:https://github.com/kongmingyang/CircleAnimationDemo/tree/master