删除部分CGPath

时间:2015-11-07 09:55:44

标签: ios swift drawing cgpath

如何删除路径的某些部分? 我在屏幕上绘制了一条路径,现在可以说我想删除1/3:

Like that

我试着这样做(路径是我的原始路径,cPath是将被剪裁的副本):

let sizePath = CGPathGetBoundingBox(path).size
UIGraphicsBeginImageContext(sizePath)
let context = UIGraphicsGetCurrentContext()
let cPath = CGPathCreateMutableCopy(path)
CGContextAddPath(context, cPath)
CGContextDrawPath(context, .Stroke)
let rect = CGRectMake(currentPosition.x, 0, sizePath.width, sizePath.height)
CGContextClipToRect(context, rect)
//How to Recive here this Clipped Path from context???

UIGraphicsEndImageContext()

但我不知道如何从我的背景中接受这条道路......

2 个答案:

答案 0 :(得分:1)

您需要先CGContextClipToRect CGContextDrawPath。剪辑区域仅影响后续绘制。

答案 1 :(得分:0)

仍然有问题没有答案,但我找到了合适的问题。要从上下文接收路径,请使用此操作: CGPathRef myPath = CGContextCopyPath(context);

相关问题