自己之前转载了一篇文章 结果发现文章内容和实际内容有差别,下面已经改正。
本节说一下 UIBezierPath 的usesEvenOddFillRule 和 CAShapeLayer的fillRule
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
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.
Table 8-2
Winding rule | Description |
nonzero, the point is inside the path and the region containing it is filled. This is the default winding rule. | |
even, the point is outside the path. If the number of crossings is odd, the point is inside the path and the region containing it should be filled. |
NSBezierPath
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
Figure 8-7 Applying winding rules to a path
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.