What is the difference between closing the bezier path using closePath function and closing it manually?

后端 未结 2 628
一个人的身影
一个人的身影 2021-02-15 10:37

I am trying to make a rectangle using UIBezierPath. I adopted two different ways to draw it. Also, I increased the stroke width to 25 px.

First method : Usin

2条回答
  •  执笔经年
    2021-02-15 11:32

    The difference is that the [closePath] method actually adds an additional path element to the underlying CGPath that backs the UIBezierPath.

    If you use [closePath], then an additional CGPathElement with a type of kCGPathElementCloseSubpath will be appended to the end of the path immediately after that last line segment.

    This is particularly important when using the [containsPoint:] method of a UIBezierPath from the docs:

    A point is not considered to be enclosed by the path if it is inside an open subpath, regardless of whether that area would be painted during a fill operation. Therefore, to determine mouse hits on open paths, you must create a copy of the path object and explicitly close any subpaths (using the closePath method) before calling this method.

提交回复
热议问题