iOS UIBezierPath知识介绍
UIBezierPath是在画图,定制动画轨迹中都有应用。
UIBezierPath有许多类方法,能够创建基本的曲线,比如利用一个rect创建一个椭圆path的方法:bezierPathWithOvalInRect。
1.看看如何绘制一个扇形路径
UIBezierPath *piePath = [UIBezierPathbezierPath];
[piePath moveToPoint:center];
[piePath addArcWithCenter:center radius:radius startAngle:topAngle endAngle:endAngle clockwise:YES];
[piePath closePath];
注意,这里的moveToPoint和closePath的使用,没有这2句话,path仅仅是一段弧,不是一个扇形。
2.利用path进行裁剪
UIBezierPath中的addClip功能:
This method modifies the visible drawing area of the current graphics context. After calling it, subsequent drawing operations result in rendered content only if they occur within the fill area of the specified path.
简单的说,就是一个path调用addClip之后,它所在的context的可见区域就变成了它的“fill area”,接下来的绘制,如果在这个区域外都会被无视。
比如,如果在上边的代码上边加上一段代码,就能实现圆弧的绘制,而不是扇形:
UIBezierPath *circlePath = [UIBezierPath bezierPathWithOvalInRect:outCircleRect];
UIBezierPath *innerCirclePath = [UIBezierPath bezierPathWithOvalInRect:innerCircleRect];
[circlePath appendPath:innerCirclePath];
[circlePath setUsesEvenOddFillRule:YES]; //后便会有说明
[circlePath addClip];
3.usesEvenOddFillRule 判断“fill area”(填充区域)的方法
如何判断一个闭合path的填充区域呢,苹果通过usesEvenOddFillRule属性,提供2中方法,
If YES, the path is filled using the even-odd rule. If NO, it is filled using the non-zero rule. Both rules are algorithms to determine which areas of a path to fill with the current fill color. A ray is drawn from a point inside a given region to a point anywhere outside the path’s bounds. The total number of crossed path lines (including implicit path lines) and the direction of each path line are then interpreted as follows:
For the even-odd rule, if the total number of path crossings is odd, the point is considered to be inside the path and the corresponding region is filled. If the number of crossings is even, the point is considered to be outside the path and the region is not filled.
For the non-zero rule, the crossing of a left-to-right path counts as +1 and the crossing of a right-to-left path counts as -1. If the sum of the crossings is nonzero, the point is considered to be inside the path and the corresponding region is filled. If the sum is 0, the point is outside the path and the region is not filled.
简单的说下,第一种,even-odd ,判断某点在不在fill area,需要从这点起,向区域外某一点画射线,如果射线和奇数条path相交,那么这点是在fill area,反之,不在。
第二种,也是画射线,根据path的顺时针和逆时针个数计算,如果和不为0,就是在fill area,反之,不在。
4.containsPoint:判断是否包含某点
The receiver contains the specified point if that point is in a portion of a closed subpath that would normally be painted during a fill operation.
iOS UIBezierPath知识介绍的更多相关文章
- iOS UIBezierPath类 介绍
使用UIBezierPath类可以创建基于矢量的路径,这个类在UIKit中.此类是Core Graphics框架关于path的一个封装.使用此类可以定义简单的形状,如椭圆或者矩形,或者有多个直线和 ...
- iOS动画之iOS UIBezierPath类 介绍
感谢:http://blog.csdn.net/crayondeng/article/details/11093689 使用UIBezierPath类可以创建基于矢量的路径,这个类在UIKit中.此类 ...
- Swift Playgrounds for mac基础知识介绍
Swift Playgrounds是一款适用于iPad和Mac的革命性应用程序,它使Swift学习变得互动而有趣.它不需要编码知识,因此非常适合刚开始的学生.使用Swift解决难题,以掌握基本知识.S ...
- [推荐]dubbo分布式服务框架知识介绍
[推荐]dubbo分布式服务框架知识介绍 CentOS+Jdk+Jboss+dubbo+zookeeper集群配置教程 http://wenku.baidu.com/view/20e8f36bf ...
- [推荐]Zookeeper大型分布式系统的可靠协调系统知识介绍
[推荐]Zookeeper大型分布式系统的可靠协调系统知识介绍 基于Zookeeper的锁开发手册 http://wenku.baidu.com/view/acbb8fc6102de2bd960588 ...
- [推荐]DDOS攻击与防范知识介绍
[推荐]DDOS攻击与防范知识介绍 DDOS攻防体系建设v0.2(淘宝-林晓曦) http://wenku.baidu.com/view/39549a11a8114431b90dd866.ht ...
- [推荐]WebService开发知识介绍
[推荐]WebService开发知识介绍 WebService开发手册 http://wenku.baidu.com/view/df3992ce050876323112128a.html WebSe ...
- iOS Simulator功能介绍关于Xamarin IOS开发
iOS Simulator功能介绍关于Xamarin IOS开发 iOS Simulator功能介绍 在图1.38所示的运行效果中,所见到的类似于手机的模型就是iOS Simulator.在没有iPh ...
- [转] - Linux网络编程 -- 网络知识介绍
(一)Linux网络编程--网络知识介绍 Linux网络编程--网络知识介绍客户端和服务端 网络程序和普通的程序有一个最大的区别是网络程序是由两个部分组成的--客户端和服务器端. 客户 ...
随机推荐
- BZOJ1432 [ZJOI2009]Function
Description Input 一行两个整数n; k. Output 一行一个整数,表示n 个函数第k 层最少能由多少段组成. Sample Input 1 1 Sample Output 1 H ...
- Mac OS下编写对拍程序
介绍 对拍是信息学竞赛中重要的技巧,它通过一个效率低下但正确率可以保证的程序,利用庞大的随机生成数据来验证我们的高级算法程序.对拍最大的优势在于可以通过人力所不能及的速度和数量达到验证的效果.下面我们 ...
- KVM切换声音关闭
Scroll Lock 2次+左右键 实现切换 Scroll Lock 2次+"B" 实现声音的开关
- PHP高效率写法(详解原因)
1.尽量静态化: 如果一个方法能被静态,那就声明它为静态的,速度可提高1/4,甚至我测试的时候,这个提高了近三倍.当然了,这个测试方法需要在十万级以上次执行,效果才明显.其实静态方法和非静态方法的效率 ...
- hdu 2041 超级楼梯
斐波那契数列,看清题意,当前为第一阶,给出M(每次只能跨1阶或2阶) 从第一阶到M,若M=1,从1-1不用走,0种方法 若M=2 从1-2 一种方法 -> 1.走一次一阶 若M=3 从1-3 ...
- unity3d下载Obb分包文件
下载OBB插件包 http://pan.baidu.com/s/1c0ouRZE 1.导入插件 注意事项: 如果项目中已经存在Android 插件,需要merge导入的xml文件例如 AndroidM ...
- VS2012变化的快捷键:
VS2012变化的快捷键: 注释::VS2010是(Ctrl+E,C),VS2012是(Ctrl+K, Ctrl+C),实际操作,按住Ctrl键不放,先按K键,再按C键.相当于Ctrl+K加 Ctrl ...
- Linux unzip解压文件到某个目录下面
1,例如我想解压Metinfo5.2.zip 到某一个文件夹下,执行下面的命令就可以了 sudo unzip MetInfo5.2.zip -d metinfo-bak
- 使用node.js制作简易爬虫
最近看了些node.js方面的知识,就像拿它来做些什么.因为自己喜欢摄影,经常上蜂鸟网,所以寻思了一下,干脆做个简单的爬虫来扒论坛的帖子. 直接上代码吧. var sys = require(&quo ...
- mysql查询在一张表不在另外一张表的记录
mysql查询在一张表不在另外一张表的记录 问题: 查询一个表(tb1)的字段记录不在另一个表(tb2)中 条件:tb1的字段key的值不在tbl2表中 -------- ...