CAShapeLayer的绘制
2016-04-24 16:17
363 查看
第一,绘制一个动画柱状图
第二,绘制一个圆形进度条
第三,设置UIBezierPath的起点
完成对曲线的绘制
//创建路径 UIBezierPath *bezierPath = [UIBezierPath bezierPath]; [bezierPath moveToPoint:CGPointMake(10, 350)]; [bezierPath addLineToPoint:CGPointMake(10, 100)]; //创建图层 CAShapeLayer *shape = [[CAShapeLayer alloc] init]; shape.fillColor = [UIColor greenColor].CGColor; shape.frame = CGRectMake(50, 50, 20, 350); shape.strokeColor = [UIColor redColor].CGColor; shape.borderColor = [UIColor orangeColor].CGColor; shape.strokeStart = 0.0; shape.strokeEnd = 1.0; shape.lineWidth = 20; shape.backgroundColor = [UIColor greenColor].CGColor; shape.path = bezierPath.CGPath; [self.view.layer addSublayer:shape]; //创建动画 CABasicAnimation *anim = [CABasicAnimation animation]; anim.keyPath = @"strokeEnd"; anim.duration = 2.0f; anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]; anim.fromValue = [NSNumber numberWithFloat:0.0]; anim.toValue = [NSNumber numberWithFloat:1.0f]; anim.autoreverses = NO; [shape addAnimation:anim forKey:@"strokeEnd"];
第二,绘制一个圆形进度条
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 100, 100)]; self.shapeLayer = [CAShapeLayer layer]; self.shapeLayer.frame = CGRectMake(100, 200, 100, 100); self.shapeLayer.backgroundColor = [UIColor clearColor].CGColor; self.shapeLayer.path = path.CGPath; self.shapeLayer.fillColor = [UIColor clearColor].CGColor; self.shapeLayer.lineWidth = 5.f; self.shapeLayer.strokeStart = 0.f; self.shapeLayer.strokeEnd = 1.0f; self.shapeLayer.strokeColor = [UIColor blackColor].CGColor; [self.view.layer addSublayer:self.shapeLayer]; CABasicAnimation *anim = [CABasicAnimation animation]; anim.keyPath = @"strokeEnd"; anim.duration = 2.0f; anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]; anim.fromValue = [NSNumber numberWithFloat:0.0]; anim.toValue = [NSNumber numberWithFloat:1.0f]; anim.autoreverses = NO; [self.shapeLayer addAnimation:anim forKey:@"strokeEnd"];
第三,设置UIBezierPath的起点
UIBezierPath *path = [UIBezierPath bezierPath]; [path moveToPoint:CGPointMake(70, 80)];设置结束点和控制点
[path addQuadCurveToPoint:CGPointMake(150, 150) controlPoint:CGPointMake(100, 150)]; [path addQuadCurveToPoint:CGPointMake(200, 150) controlPoint:CGPointMake(50, 200)];
完成对曲线的绘制
相关文章推荐
- IOS设计模式--策略模式
- java泛型类和泛型函数
- android 中通过代码创建控件
- C++中的RTTI机制解析
- Swift中的?与!(Optional Type)
- shell和python实现时间转化
- 求改错,题目如下:求n个整数中第二小的数。 相同的整数看成一个数。比如,有5个数分别是1,1,3,4,5,那么第二小的数就是3。
- exe4教程
- vtk实战(一)——HelloVtk
- Eclipse快捷键大全
- equals和hashCode
- 数据结构实验二 栈、队列
- arc中dealloc方法不调用
- 网络参考模型: OSI参考模型;TCP/IP参考模型
- Git学习2:为什么工作区目录下有.git目录
- exe4教程
- 素数环问题,深度搜索
- 实验二作业调度模拟程序
- wc命令----统计指定文件中的字节数、字数、行数
- 浅析jQuery删除节点的三个方法