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知识介绍的更多相关文章

  1. iOS UIBezierPath类 介绍

      使用UIBezierPath类可以创建基于矢量的路径,这个类在UIKit中.此类是Core Graphics框架关于path的一个封装.使用此类可以定义简单的形状,如椭圆或者矩形,或者有多个直线和 ...

  2. iOS动画之iOS UIBezierPath类 介绍

    感谢:http://blog.csdn.net/crayondeng/article/details/11093689 使用UIBezierPath类可以创建基于矢量的路径,这个类在UIKit中.此类 ...

  3. Swift Playgrounds for mac基础知识介绍

    Swift Playgrounds是一款适用于iPad和Mac的革命性应用程序,它使Swift学习变得互动而有趣.它不需要编码知识,因此非常适合刚开始的学生.使用Swift解决难题,以掌握基本知识.S ...

  4. [推荐]dubbo分布式服务框架知识介绍

    [推荐]dubbo分布式服务框架知识介绍 CentOS+Jdk+Jboss+dubbo+zookeeper集群配置教程    http://wenku.baidu.com/view/20e8f36bf ...

  5. [推荐]Zookeeper大型分布式系统的可靠协调系统知识介绍

    [推荐]Zookeeper大型分布式系统的可靠协调系统知识介绍 基于Zookeeper的锁开发手册 http://wenku.baidu.com/view/acbb8fc6102de2bd960588 ...

  6. [推荐]DDOS攻击与防范知识介绍

    [推荐]DDOS攻击与防范知识介绍 DDOS攻防体系建设v0.2(淘宝-林晓曦)     http://wenku.baidu.com/view/39549a11a8114431b90dd866.ht ...

  7. [推荐]WebService开发知识介绍

    [推荐]WebService开发知识介绍 WebService开发手册  http://wenku.baidu.com/view/df3992ce050876323112128a.html WebSe ...

  8. iOS Simulator功能介绍关于Xamarin IOS开发

    iOS Simulator功能介绍关于Xamarin IOS开发 iOS Simulator功能介绍 在图1.38所示的运行效果中,所见到的类似于手机的模型就是iOS Simulator.在没有iPh ...

  9. [转] - Linux网络编程 -- 网络知识介绍

    (一)Linux网络编程--网络知识介绍 Linux网络编程--网络知识介绍客户端和服务端         网络程序和普通的程序有一个最大的区别是网络程序是由两个部分组成的--客户端和服务器端. 客户 ...

随机推荐

  1. 【poj3020】 Antenna Placement

    http://poj.org/problem?id=3020 (题目链接) 题意 给出一个矩阵,矩阵中只有‘*’和‘o’两种字符,每个‘*’可以向它上下左右四个方位上同为‘*’的点连一条边,求最少需要 ...

  2. ajax提交特殊字符的处理

    前台页面用encodeURIComponent()这个js方法 rule=encodeURIComponent(rule);//对特殊字符编码 后台页面 java.net.URLDecoder url ...

  3. HD2157How many wasy??(十大矩阵问题之八 + 邻接矩阵的应用)

    How many ways?? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  4. Laravel教程 三:视图变量传递和Blade

    Laravel教程 三:视图变量传递和Blade 此文章为原创文章,未经同意,禁止转载. Blade 上一篇我们简单地说了Router,Views和Controllers的工作流程,这一次我就按照上一 ...

  5. Python序列的切片操作与技巧

    切片操作 对于具有序列结构的数据来说,切片操作的方法是:consequence[start_index: end_index: step]. start_index: 表示是第一个元素对象,正索引位置 ...

  6. 转 web项目中的web.xml元素解析

    转 web项目中的web.xml元素解析 发表于1年前(2014-11-26 15:45)   阅读(497) | 评论(0) 16人收藏此文章, 我要收藏 赞0 上海源创会5月15日与你相约[玫瑰里 ...

  7. Struts2拦截器的应用

    拦截器类 public class AdminInterceptor extends AbstractInterceptor { private static final long serialVer ...

  8. WPF 组合快捷键

    if(e.KeyStates == Keyboard.GetKeyStates(Key.F4) && Keyboard.Modifiers == ModifierKeys.Alt) { ...

  9. Hibernate3的DetachedCriteria支持

    Hibernate3支持DetachedCriteria,这是一个非常有意义的特性!我们知道,在常规的Web编程中,有大量的动态条件查询,即用户在网页上面自由选择某些条件,程序根据用户的选择条件,动态 ...

  10. 整理时下流行的浏览器User-Agent大全

    总结整理时下流行的浏览器User-Agent大全 此文章转至:http://www.360doc.com/content/12/1012/21/7662927_241124973.shtml 用于学习 ...