UIView圆形蒙版动画

UIView circle mask animation

我有一个抽象的奇怪形状的 UIView。 我需要显示一个 平滑 外观动画。

我想我应该将该动画应用于该视图上方的蒙版。 面具将是圆形的。 所以用户将看到 1'2'3'4' 序列。 我该如何实施? 我想我应该应用一些仿射变换 到蒙版视图。那么,口罩原本的形状应该是怎样的呢? 垂直线?

一个简单的例子,假设我有一个 100*100 imageview,

注意:为简单起见,我使用硬编码数字

 CAShapeLayer * maskLayer = [CAShapeLayer layer];
maskLayer.bounds = CGRectMake(0, 0, 100, 100);
maskLayer.position = CGPointMake(50, 50);
UIBezierPath * path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(50.0, 50.0) radius:50 startAngle:0 endAngle:M_PI *2 clockwise:true];
maskLayer.path = path.CGPath;
maskLayer.fillColor = [UIColor clearColor].CGColor;
maskLayer.strokeColor = [UIColor blackColor].CGColor;
maskLayer.strokeEnd = 0.0;
maskLayer.lineWidth = 100;
self.imageview.layer.mask = maskLayer;

CABasicAnimation * animation = [CABasicAnimation animation];
animation.keyPath = @"strokeEnd";
animation.toValue = @(1.0);
animation.duration = 2.0;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
animation.fillMode = kCAFillModeForwards;
animation.removedOnCompletion = NO;

[maskLayer addAnimation:animation forKey:@"keyFrame"];