![](https://img.haomeiwen.com/i1780916/8d5fea18470a91f1.gif)
核心代码:
// 宏
#define TimerPerTime 0.01
#define TotalTime 0.75
// 属性初始化
self.radius = WINDOW_height * 0.5;
self.perH = TimerPerTime / TotalTime * self.radius;
// 按钮点击事件
self.timer = [NSTimer scheduledTimerWithTimeInterval:TimerPerTime target:self selector:@selector(updateAnim) userInfo:nil repeats:YES];
// 定时器事件
- (void)updateAnim{
self.radius = self.radius - self.perH;
[self round:self.radius];
}
- (void)round:(CGFloat)radius{
UIBezierPath *circlePath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.center.x, self.center.y)
radius:radius
startAngle:0
endAngle:2 * M_PI
clockwise:NO];
CAShapeLayer *shaperLayer = [CAShapeLayer layer];
shaperLayer.path = circlePath.CGPath;
self.layer.mask = shaperLayer;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(TotalTime * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.timer invalidate];
self.timer = nil;
[self removeFromSuperview];
});
}
![](https://img.haomeiwen.com/i1780916/4b7e0c58e51dc4c9.gif)
核心代码:
// 属性初始化
self.radius = 0;
self.perH = TimerPerTime / TotalTime * WINDOW_height;
// 按钮点击事件
self.timer = [NSTimer scheduledTimerWithTimeInterval:TimerPerTime target:self selector:@selector(updateAnim) userInfo:nil repeats:YES];
// 定时器事件
- (void)updateAnim{
self.radius = self.radius + self.perH;
[self round:self.radius];
}
- (void)round:(CGFloat)radius{
UIBezierPath *path = [UIBezierPath bezierPathWithRect:self.bounds];
UIBezierPath *circlePath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.center.x, self.center.y)
radius: radius
startAngle:0
endAngle:2 * M_PI
clockwise:NO];
[path appendPath:circlePath];
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.path = path.CGPath;
self.layer.mask = shapeLayer;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(TotalTime * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.timer invalidate];
self.timer = nil;
[self removeFromSuperview];
});
}
网友评论