裁剪 CGPathRef 或 UIBezierPath

Clipping a CGPathRef or UIBezierPath

鉴于我有一个 CGPathRef,或一个 UIBezierPath,或其他一些等效的 iOS 表示,是否有内置的库函数可用于计算片段这个对象给我?

注意 澄清一下,我不是要求能够绘制一条路径与剪辑。我想获得一个实际的剪切路径,作为一个新路径。

查看我对 . I wrote a library that will let you calculate the intersections between any two UIBezierPath and calculate the clipped path between them. The library is at https://github.com/adamwulf/ClippingBezier 的类似回答。

虽然其他问题涉及形状的交集,但您也可以简单地将两条路径拆分为组成部分。

NSArray* clippedPathSegments = [UIBezierPath redAndGreenAndBlueSegmentsCreatedFrom:path1 bySlicingWithPath:path2 andNumberOfBlueShellSegments:NULL];

该方法的名称有点尴尬,它在内部用于更好命名的 uniqueShapesCreatedFromSlicingWithUnclosedPath: 方法,但应该做您想要的。