bla*_*cos 8 core-graphics ios uibezierpath
我正在尝试使用矩形UIBezierPath.我采用了两种不同的方法来绘制它.另外,我将笔画宽度增加到25像素.
第一种方法:使用closePath
UIBezierPath *bpath = [UIBezierPath bezierPath];
[bpath moveToPoint:CGPointMake(x, y)];
[bpath addLineToPoint:CGPointMake(x + w, y)];
[bpath addLineToPoint:CGPointMake(x + w, y + h)];
[bpath addLineToPoint:CGPointMake(x, y + h)];
[bpath closePath];
Run Code Online (Sandbox Code Playgroud)
输出:

第二种方法:手动关闭路径
UIBezierPath *bpath = [UIBezierPath bezierPath];
[bpath moveToPoint:CGPointMake(x, y)];
[bpath addLineToPoint:CGPointMake(x + w, y)];
[bpath addLineToPoint:CGPointMake(x + w, y + h)];
[bpath addLineToPoint:CGPointMake(x, y + h)];
[bpath addLineToPoint:CGPointMake(x, y)];
Run Code Online (Sandbox Code Playgroud)
输出:

在closePath它的文档中说This method closes the current subpath by creating a line segment between the first and last points in the subpath. This method subsequently updates the current point to the end of the newly created line segment, which is also the first point in the now closed subpath.
在第二种方法中,我创建了第一个和最后一个点之间的线段.那么,为什么第二种方法矩形没有被完全描边?
注意:这些方法之间的差异仅在笔划宽度显着增加时才可见.
不同之处在于该[closePath]方法实际上向支持UIBezierPath的底层CGPath添加了一个额外的路径元素.
如果您使用[closePath],则会在最后一个线段之后立即将附加CGPathElement类型的kCGPathElementCloseSubpath附加内容附加到路径的末尾.
当使用UIBezierPath文档中的[containsPoint:]方法时,这一点尤其重要:
如果一个点位于打开的子路径内,则该路径不被视为包围,无论该区域是否在填充操作期间被绘制.因此,要确定打开路径上的鼠标命中,必须先创建路径对象的副本,然后在调用此方法之前显式关闭所有子路径(使用closePath方法).
| 归档时间: |
|
| 查看次数: |
1654 次 |
| 最近记录: |