iOS UIBezierPath 路径裁剪
2016-03-04 20:31
399 查看
http://www.cnblogs.com/breezemist/p/3487770.html
UIBezierPath是在画图,定制动画轨迹中都有应用。
UIBezierPath有许多类方法,能够创建基本的曲线,比如利用一个rect创建一个椭圆path的方法:bezierPathWithOvalInRect。
1.看看如何绘制一个扇形路径
注意,这里的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 thefill
area of the specified path.
简单的说,就是一个path调用addClip之后,它所在的context的可见区域就变成了它的“fill area”,接下来的绘制,如果在这个区域外都会被无视。
比如,如果在上边的代码上边加上一段代码,就能实现圆弧的绘制,而不是扇形:
3.usesEvenOddFillRule 判断“fill area”(填充区域)的方法
如何判断一个闭合path的填充区域呢,苹果通过usesEvenOddFillRule属性,提供2中方法,
If
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.
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 thefill
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.
相关文章推荐
- ue4点滴
- Java StringBuilder & StringBuffer 源代码分析
- USACO 之 Section 1.4 More Search Techniques (已解决)
- 华为EMUI4.0 基于android 6.0的bug
- BlockingQueue
- Android源码浅析: Message/Handler/MessageQueue/Looper
- PAT (Advanced Level) Practise 1017 Queueing at Bank (25)
- [hdu4010]: Query on The Trees
- SPOJ QTREE Query on a tree [树链剖分+线段树]
- NSOperationQueue与GCD的使用原则和场景
- Android自动化测试(UiAutomator)介绍与学习
- UGUI源码学习之初涉Button(三)
- UIBezierPath精讲
- 消息队列ActiveMQ(一)——Queue方式和Topic方式
- require 加载机制
- UGUI源码学习之初涉Text(二)
- UITableView的全选和多选功能
- EasyUI Combobox 二级联动
- HBuilder实现软件自动升级
- 利用UIWindow自定义类似UIAlertView的弹出框