关于CAShapeLayer的一些基本操作

设置圆形进度条:

实现效果如下:

 

实现代码如下:(注释很详细啦!!!)

 1  UIView *circleView = [[UIView alloc]initWithFrame:CGRectMake(40, 200, 100, 100)];
 2     shapeView.backgroundColor = [UIColor greenColor];
 3     [self.view addSubview:circleView];
 4     
 5     // 实现圆形进度条
 6     
 7     CAShapeLayer *shapeLayer =[CAShapeLayer layer];
 8     shapeLayer.frame = circleView.bounds;
 9     //绘制
10     UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:circleView.bounds];
11     shapeLayer.path = path.CGPath;
12     // 设置填充颜色
13     shapeLayer.fillColor = [UIColor greenColor].CGColor;
14     // 设置线条宽度
15     shapeLayer.lineWidth = 2.0f;
16     // 设置线条颜色
17     shapeLayer.strokeColor = [UIColor redColor].CGColor;
18     [circleView.layer addSublayer:shapeLayer];
19     
20     // 设置基础动画
21     CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
22     pathAnimation.duration = 3.0;
23     pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
24     pathAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
25     pathAnimation.toValue = [NSNumber numberWithFloat:1.0f];
26     pathAnimation.fillMode = kCAFillModeForwards;
27     pathAnimation.removedOnCompletion = NO;
28     [shapeLayer addAnimation:pathAnimation forKey:@"strokeEndAnimation"];
29     

 

最后记录一个警告的意思和处理方法:

 

如果出现上面的这警告问题,原因是:

这个往往是复制网上的带格式的代码导致的。

解决办法:

在提示的地方进行换行处理,首先先选中提示的"_".然后按回车键即可。

最好的方法还是自己敲代码比较合适,不复制就不会出现这些警告啦!!!!

posted on 2016-07-12 10:26  玉思盈蝶  阅读(213)  评论(0编辑  收藏  举报

导航