CAShapeLayer的fillRule(转载)

自己之前转载了一篇文章 结果发现文章内容和实际内容有差别,下面已经改正。

本节说一下 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.

Table 8-2  Winding rules

Winding rule

Description

NSNonZeroWindingRule

Count each left-to-right path as +1 and each right-to-left path as -1. If the sum of all crossings is 0, the point is outside the path. If the sum isnonzero, the point is inside the path and the region containing it is filled. This is the default winding rule.

NSEvenOddWindingRule

Count the total number of path crossings. If the number of crossings is 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.

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.

Figure 8-7  Applying winding rules to a pathApplying winding rules to a path

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值