使用CAShapeLayer 的 转圈圈动画

来源:互联网 发布:淘宝优惠微信群 编辑:程序博客网 时间:2024/06/07 22:30
在View中添加一个加载动画UIView *view = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];view.backgroundColor = [UIColor whiteColor];[self.view addSubview:view];CAShapeLayer *shapeLayer = [CAShapeLayer layer];shapeLayer.frame = view.bounds;UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:view.bounds];shapeLayer.path = path.CGPath;shapeLayer.fillColor = [UIColor clearColor].CGColor;shapeLayer.lineWidth = 2;shapeLayer.strokeColor = [UIColor lightGrayColor].CGColor;[view.layer addSublayer:shapeLayer];//任何CABasicAnimation 的@keyPath 为确定的,  此处为strokeEnd//其他keyPath 参考[Ansel_m 的博客](http://blog.csdn.net/majiakun1/article/details/46426727)CABasicAnimation *pathAnima = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];pathAnima.duration = 1.0f;pathAnima.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];pathAnima.fromValue = @0.05f;pathAnima.toValue = @1.0f;pathAnima.repeatCount = 100;pathAnima.fillMode = kCAFillModeForwards;pathAnima.removedOnCompletion = NO;[shapeLayer addAnimation:pathAnima forKey:@"strokeEndAnimation"];
0 0
原创粉丝点击