我正在嘗試使用UIBezierPath
來製作一個矩形。我採用了兩種不同的方式來繪製它。此外,我增加了行程寬度爲25像素。使用closePath函數關閉貝塞爾路徑並手動關閉貝司捷路徑有什麼區別?
第一種方法:使用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];
輸出:
第二種方法:關閉路徑手動
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)];
輸出:
在文檔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.
而在第二個方法我創建第一個和最後一個點之間的線段。那麼,爲什麼在第二個方法矩形沒有完全撫摸?
注意:這些方法之間的區別僅在筆畫寬度顯着增加時纔可見。