UIBezierPath和CAShapeLayer的关系
CAShapeLayer是基于贝塞尔曲线而存在的, 如果没有贝塞尔曲线提供路径来画出图形, CAShapeLayer就没有存在的意义, CAShapeLayer可以使得不用在drawRect:方法中实现画图.
另外, CAShapeLayer是属于CoreAnimation框架的, 是基于GPU的来进行渲染的, 不比使用CoreGraphic框架, 是基于CPU来渲染的, 所以CAShapeLayer效率相对比较高一些
下面我简单的使用CAShapeLayer和贝塞尔曲线画了矩形和椭圆形, 代码如下:
#import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad
{
[super viewDidLoad]; [self createOval];
} // 矩形(正方形)
- (void)createRect
{
// 创建矩形贝塞尔曲线路径
UIBezierPath *rect = [UIBezierPath bezierPathWithRect:CGRectMake(, , , )]; // 创建CAShapeLayer
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
// 设置尺寸
shapeLayer.frame = CGRectMake(, , , );
// 设置位置
shapeLayer.position = self.view.center;
// 填充颜色
shapeLayer.fillColor = [UIColor whiteColor].CGColor;
// 路径颜色
shapeLayer.strokeColor = [UIColor blackColor].CGColor; // 关联
shapeLayer.path = rect.CGPath; // 显示
[self.view.layer addSublayer:shapeLayer];
} // 椭圆(圆)
- (void)createOval
{
// 创建椭圆形贝塞尔曲线路径
UIBezierPath *oval = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(, , , )]; // 创建CAShapeLayer
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
// 设置尺寸,
shapeLayer.frame = CGRectMake(, , , );
// 设置位置(设置的是shapeLayer的中心点位置)
shapeLayer.position = self.view.center;
// 设置背景颜色
shapeLayer.backgroundColor = [UIColor greenColor].CGColor;
// 设置填充颜色(注意, 这里不是设置背景颜色)
shapeLayer.fillColor = [UIColor redColor].CGColor;
// 设置边框颜色(路径颜色)
shapeLayer.strokeColor = [UIColor blueColor].CGColor; // 关联ShapeLayer和贝塞尔曲线
shapeLayer.path = oval.CGPath; // 显示
[self.view.layer addSublayer:shapeLayer]; }
UIBezierPath和CAShapeLayer的关系的更多相关文章
- 放肆的使用UIBezierPath和CAShapeLayer画各种图形
CAShapeLayer 是 CALayer 的子类,但是比 CALayer 更灵活,可以画出各种图形,当然,你也可以使用其他方式来画,随你. 杂谈 在 CAShapeLayer 中,也可以像 CAL ...
- 使用UIBezierPath和CAShapeLayer画各种图形
转载自:http://www.cocoachina.com/ios/20160214/15251.html CAShapeLayer 是 CALayer 的子类,但是比 CALayer 更灵活,可以画 ...
- UIBezierPath 和 CAShapeLayer 绘画图纸
五角大楼画一个小圆圈戴: - (void)drawPentagon{ //(1)UIBezierPath对象 UIBezierPath *aPath = [UIBezierPath bezierPat ...
- 贝塞尔曲线与CAShapeLayer的关系以及Stroke动画
1.贝塞尔曲线与CAShapeLayer的关系 1.1CAShapeLayer须要一个形状才干生效,贝塞尔曲线能够创建基于矢量的路径.进而能够给CAShapeLayer提供路径,路径会闭环. ...
- iOS 使用UIBezierPath和CAShapeLayer画各种图形
CAShapeLayer 是 CALayer 的子类,但是比 CALayer 更灵活,可以画出各种图形,当然,你也可以使用其他方式来画,随你. 杂谈 在 CAShapeLayer 中,也可以像 CAL ...
- UIBezierPath与CAShapeLayer结合画扇形
/*让半径等于期望半径的一半 lineWidth等于期望半径 就可以画圆*/ 可以看出layer的走势是从圆边的中间一半在圆外 一半在圆内 因此让半径等于期望半径的一半 lineWidth等于期望半径 ...
- UIBezierPath和CAShapeLayer配合肆意画图
一.CAShapeLayer CAShapeLayer 是 CALayer 的子类,但是比 CALayer 更灵活,可以画出各种图形 使用CAShapeLayer 绘制一个矩形 let layer ...
- iOS关于CAShapeLayer与UIBezierPath的知识内容
使用CAShapeLayer与UIBezierPath可以实现不在view的drawRect方法中就画出一些想要的图形 . 1:UIBezierPath: UIBezierPath是在 UIKit 中 ...
- 使用CAShapeLayer与UIBezierPath画出想要的图形
使用CAShapeLayer与UIBezierPath可以实现不在view的drawRect方法中就画出一些想要的图形 步骤: 1.新建UIBezierPath对象bezierPath 2.新建CAS ...
随机推荐
- arm的一些概念(ARM7、Cortex-M的区别)
ARM7:ARMv4架构,ARM9:ARMv5架构,ARM11:ARMv6架构,ARM-Cortex 系列:ARMv7架构. ARM7没有MMU(内存管理单元),只能叫做MCU(微控制器),不能 ...
- access数据库管理软件收集下载
access百科 Microsoft Office Access是由微软发布的关系数据库管理系统.它结合了 MicrosoftJet Database Engine 和 图形用户界面两项特点,是 Mi ...
- 使用Thumbnails对一个文件夹下的所有图片进行压缩处理
public static void compressPic(){ try { Thumbnails.of(new File("/home/y/my_temp/ydbg-xy-pic&quo ...
- bing---iis how to process http request
http://msdn.microsoft.com/en-us/library/ms524901(v=vs.90).aspx http://msdn.microsoft.com/en-us/magaz ...
- Jzzhu and Chocolate
CF#257 div2 C:http://codeforces.com/contest/450/problem/C 题意:n*m的方格,每次可以横着或者纵向的切一刀,问切k之后,最小的最大是多少. 题 ...
- 构造AJAX参数, 表单元素JSON相互转换
ajax提交服务器数据, 整理一下转换方法. HTML: <form id="fm" name="fm" action=""> ...
- 多线程Two-Phase Termination Pattern两阶段终止模式
一 Two-Phase Termination Pattern Two-Phase Termination Pattern,指的就是当希望结束一个线程的时候,送出一个终止请求,但是不会马上停止,做一些 ...
- Linux2.6内核--对块IO层操作的讨论
当一个块被调入内存时(也就是说,在读入后或等待写出时),它要存储在缓冲区中.每个缓冲区与一个块对应,它相当于是磁盘块在内存中的表示.块包含一个或多个扇区,但大小不能超过一页,所以一页可以容 ...
- 【HDOJ】1109 Run Away
基础模拟退火. /* poj 1379 */ #include <iostream> #include <cstdio> #include <cstdlib> #i ...
- 【jQuery】jQuery API 过 一 遍
closest, parents <!DOCTYPE html> <html> <head> <meta charset="utf-8"& ...