2013-06-27 26 views
0

我曾經路徑由CGMutablePathRef確定CGMutablePathRef的邊界?

CGMutablePathRef pointsPathpath = CGPathCreateMutable(); 
    CGPathMoveToPoint(pointsPathpath, NULL, firstPoint.x, firstPoint.y); 
    CGPathAddLineToPoint(pointsPathpath, NULL, secondPoint.x, secondPoint.y); 
    CGPathAddLineToPoint(pointsPathpath, NULL, thirdPoint.x, thirdPoint.y); 
    CGPathAddLineToPoint(pointsPathpath, NULL, fourthPoint.x, fourthPoint.y); 
    CGPathCloseSubpath(pointsPathpath); 

做有什麼辦法得到它的邊界點?

在此先感謝。

回答

3

核心圖形具有兩個方法來計算CGPath的「邊界框」。

  1. CGPathGetPathBoundingBox()
  2. CGPathGetBoundingBox()

第一個返回封閉路徑中的所有的點,但不包括對於曲線控制點的最小邊界框。

第二個確實包括曲線的控制點。

您的路徑沒有任何曲線,因此它們都會返回相同的矩形,但對於更高級的路徑,它們通常會返回不同的區域。

下圖顯示了它們的區別。帶圓圈的黑色線條最終是路徑中曲線的控制點。

enter image description here