iOS中下载指示剂,一个点转圈圈
2018-01-06 本文已影响0人
骑着雅迪小毛驴上班的老瞿
1.在下载过程中,对于文件比较的下载,在还没有开始下载前,我们一般需要来一个指示图像,下载过程中我们就显示下载的进度,这里我们来使用UIBezierPath和CAKeyframeAnimation做一个简单的动画转圈圈效果
1.gif
2.上代码.由于代码功能主要是实现在下载过程的进度,针对只要转圈圈可能有几句代码不需要,请自己酌情处理
#import "loopView.h"
#import "UIView+HHAddition.h"
@interface loopView()
@property (nonatomic,strong)CALayer *animationCircle;
@end
@implementation loopView
-(void)drawRect:(CGRect)rect{
[super drawRect:rect];
CGPoint center = CGPointMake(self.width * 0.5, self.height * 0.5);
UIBezierPath *backPath = [UIBezierPath bezierPathWithArcCenter:center radius:self.width * 0.25 startAngle:0 endAngle:2 * M_PI clockwise:YES];
backPath.lineWidth = 2;
[[UIColor whiteColor] set];
[backPath stroke];
[self.layer addSublayer:self.animationCircle];
CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.calculationMode = kCAAnimationPaced;
pathAnimation.fillMode = kCAFillModeForwards;
pathAnimation.removedOnCompletion = NO;
pathAnimation.duration = 4.0;
pathAnimation.repeatCount = 10000;
pathAnimation.path = backPath.CGPath;
[self.animationCircle addAnimation:pathAnimation forKey:nil];
}
- (CALayer *)animationCircle{
if (!_animationCircle) {
_animationCircle = [CALayer layer];
_animationCircle.frame = CGRectMake(0, 0, 4, 4);
_animationCircle.cornerRadius = 2;
_animationCircle.backgroundColor = [UIColor blueColor].CGColor;
}
return _animationCircle;
}
@end