0

我有 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);

有没有办法得到它的边界点?

提前致谢。

4

2 回答 2

3

Core Graphics 有两种方法来计算 CGPath 的“边界框”。

  1. CGPathGetPathBoundingBox()
  2. CGPathGetBoundingBox()

第一个返回包含路径中所有点但包括曲线控制点的最小边界框。

第二个确实包括曲线的控制点。

您的路径没有任何曲线,因此它们都将返回相同的矩形,但对于更高级的路径,它们通常返回不同的区域。

下图说明了它们的区别。最后带圆圈的黑线是路径中曲线的控制点。

在此处输入图像描述

于 2013-06-27T18:13:01.050 回答
1

您可以使用 CGPathGetBoundingBox() 或 CGPathGetPathBoundingBox()。

这两个都列在 CGPath 文档中:http: //developer.apple.com/library/ios/#documentation/graphicsimaging/Reference/CGPath/Reference/reference.html

于 2013-06-27T16:55:04.683 回答