# iOS UIBezierPath知识介绍

UIBezierPath是在画图，定制动画轨迹中都有应用。

UIBezierPath有许多类方法，能够创建基本的曲线，比如利用一个rect创建一个椭圆path的方法：bezierPathWithOvalInRect。

1.看看如何绘制一个扇形路径

 UIBezierPath *piePath = [UIBezierPathbezierPath];
[piePath moveToPoint:center];
[piePath closePath];

2.利用path进行裁剪

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.

UIBezierPath *circlePath = [UIBezierPath bezierPathWithOvalInRect:outCircleRect];
UIBezierPath *innerCirclePath = [UIBezierPath bezierPathWithOvalInRect:innerCircleRect];
[circlePath appendPath:innerCirclePath];
[circlePath setUsesEvenOddFillRule:YES];  //后便会有说明
[circlePath addClip];

3.usesEvenOddFillRule 判断“fill area”（填充区域）的方法

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.

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.

posted @ 2013-12-23 17:11 幻化成疯 阅读(...) 评论(...) 编辑 收藏