Sto provando a creare un rettangolo utilizzando UIBezierPath
. Ho adottato due modi diversi per disegnarlo. Inoltre, ho aumentato la larghezza del tratto a 25 px.Qual è la differenza tra la chiusura del percorso di Bezier con la funzione closePath e la chiusura manuale?
Primo metodo: Utilizzo 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];
uscita:
Secondo metodo: chiusura del percorso 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)];
uscita:
Nella documentazione per closePath
si dice 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.
E in secondo metodo che sto creando il segmento di linea tra il primo e l'ultimo punto. Quindi, perché nel secondo metodo il rettangolo non è completamente accarezzato?
Nota: la differenza tra questi metodi è visibile solo quando la larghezza della corsa aumenta significativamente.