Qual é a diferença entre fechar o caminho do bezier usando a função closePath e fechá-lo manualmente?
Estou tentando fazer um retângulo usandoUIBezierPath
. Eu adotei duas maneiras diferentes de desenhá-lo. Além disso, aumentei a largura do traçado para 25 px.
Primeiro método: Usando 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];
Resultado:
Segundo método: Fechando o caminho manualmente
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)];
Resultado:
Na documentação paraclosePath
dizThis 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.
E no segundo método, estou criando o segmento de linha entre o primeiro e o último ponto. Então, por que no segundo método o retângulo não é completamente acariciado?
Nota: A diferença entre esses métodos é visível apenas quando a largura do curso é aumentada significativamente.