自己之前转载了一篇文章 结果发现文章内容和实际内容有差别,下面已经改正。
本节说一下 UIBezierPath 的usesEvenOddFillRule 和 CAShapeLayer的fillRule
http://blog.csdn.net/jeffasd/article/details/51602946
UIBezierPath的userEvenOddFillRule 是对路径来说的,对于CAShapeLayer的填充效果是没有作用的,CAShapeLayer的填充效果只和自己的自己的fillRule和其内部路径的走向有关,起fillRule 有 even-odd 和 non-zero
/* The fill rule used when filling the path. Options are `non-zero' and
* `even-odd'. Defaults to `non-zero'. */
even-odd 奇偶判断规则,从任意一点出发 与边界交点个数为 奇数则表示在圆或者说图形内,如果为偶数表示在圆外或者说图形外
奇数时在圆内
non-zero 非0判断规则,从任意一点出发,与边界交点个数为不为0时表示在圆内,为0表示在圆外,
不为0在圆内
从某种意义上说,even-odd和non-zero规则判断在不在圆内,其结果正好相反。
Winding Rules
When you fill the area encompassed by a path, NSBezierPath
applies the current winding rule to determine which areas of the screen to fill. A winding rule is simply an algorithm that tracks information about each contiguous region that makes up the path's overall fill area. A ray is drawn from a point inside a given region to any point outside the path bounds. The total number of crossed path lines (including implicit lines) and the direction of each path line are then interpreted using the rules in Table 8-2, which determine if the region should be filled.
Fill operations are suitable for use with both open and closed subpaths. A closed subpath is a sequence of drawing calls that ends with a Close Path path element. An open subpath ends with a Move To path element. When you fill a partial subpath, NSBezierPath
closes it for you automatically by creating an implicit (non-rendered) line from the first to the last point of the subpath.
Figure 8-7 shows how the winding rules are applied to a particular path. Subfigure a
shows the path rendered using the nonzero rule and subfigure b
shows it rendered using the even-odd rule. Subfigures c
and d
add direction marks and the hidden path line that closes the figure to help you see how the rules are applied to two of the path’s regions.

To set the winding rule for an NSBezierPath
object, use the setWindingRule:
method. The default winding rule is NSNonZeroWindingRule
. To change the default winding rule for all NSBezierPath
objects, use the setDefaultWindingRule:
method.