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. UVA5876 Writings on the Wall 扩展KMP

    扩展KMP的简单题. #include<stdio.h> #include<string.h> #define maxn 51010 char s[maxn],t[maxn]; ...

  2. java基础-关键字-native

     一. 什么是Native Method    简单地讲,一个Native Method就是一个java调用非java代码的接口.一个Native Method是这样一个java的方法:该方法的实现由 ...

  3. CSS3媒体查询

    随着响应式设计模型的诞生,Web网站又要发生翻天腹地的改革浪潮,可能有些人会觉得在国内IE6用户居高不下的情况下,这些新的技术还不会广泛的蔓延下去,那你就错了,如今淘宝,凡客,携程等等公司都已经在大胆 ...

  4. Oracle 调度程序(scheduler)摘自一位大神

    在11g中,Oracle提供了一个新建的Scheduler特性,帮助将作业实现自动化.它还可以帮助你控制资源的利用与并可以将数据库中的作业按优先顺序执行.传统的dbms_jobs的一个限制是它只能调度 ...

  5. BZOJ2818 欧拉函数

    题意:求1--n中满足gcd(x,y)的值为质数的数对(x,y)的数目 ( (x,y)和(y,x)算两个 ) sol: 设p[i]是一个质数,那么以下两个命题是等价的: 1.gcd(x,y)=1 2. ...

  6. 洛谷P2320 [HNOI2006]鬼谷子的钱袋

    https://www.luogu.org/problem/show?pid=2320#sub 题目描述全是图 数学思维,分治思想 假设总数为n 从n/2+1到n的数都可以用1~n的数+n/2表示出来 ...

  7. HDU 2255 奔小康发大财

    传送门 Solution: KM算法 关于KM算法有一篇极好的文档http://www.cse.ust.hk/~golin/COMP572/Notes/Matching.pdf Implementat ...

  8. 使用Jquery+EasyUI 进行框架项目开发案例讲解之五 模块(菜单)管理源码分享

    http://www.cnblogs.com/huyong/p/3454012.html 使用Jquery+EasyUI 进行框架项目开发案例讲解之五  模块(菜单)管理源码分享    在上四篇文章 ...

  9. CentOS 设置网络(修改IP&修改网关&修改DNS)--update.14.08.15

    自己电脑上装的虚拟机用桥接方式连接物理机,虚拟机重启后ip会发生变化,非常阻碍Xshell的连接和hosts指定的dns. 通过修改IP为static模式,保持IP不变. ============== ...

  10. C#编程总结 dynamic(转)

    介绍 Visual C# 2010 引入了一个新类型 dynamic. 该类型是一种静态类型,但类型为 dynamic 的对象会跳过静态类型检查. 大多数情况下,该对象就像具有类型 object 一样 ...