ios - 如何在同一视图中使用两个bezier路径?

时间:2014-04-18 12:32:27

标签: ios uibezierpath

我正在使用UIBezierPath在我的图像中剪切一个洞。

UIBezierPath *currentPath = [UIBezierPath bezierPath];

    CGPoint tempPoint = CGPointMake(leftEyePos.x+30,leftEyePos.y-25);
    [currentPath moveToPoint:CGPointMake(tempPoint.x, tempPoint.y)];
    tempPoint = CGPointMake(leftEyePos.x-40,leftEyePos.y-25);
    [currentPath addLineToPoint:CGPointMake(tempPoint.x, tempPoint.y)];
    tempPoint = CGPointMake(leftEyePos.x-40,leftEyePos.y+10);
    [currentPath addLineToPoint:CGPointMake(tempPoint.x, tempPoint.y)];
    tempPoint = CGPointMake(leftEyePos.x+30,leftEyePos.y+10);
    [currentPath addLineToPoint:CGPointMake(tempPoint.x, tempPoint.y)];
    tempPoint = CGPointMake(leftEyePos.x+30, leftEyePos.y-25);
    [currentPath addLineToPoint:CGPointMake(tempPoint.x, tempPoint.y)];

和这个

// Create an image context containing the original UIImage.
    UIGraphicsBeginImageContext(filteredImage.size);
    [filteredImage drawAtPoint:CGPointZero];

    // Clip to the bezier path and clear that portion of the image.
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextAddPath(context,currentPath.CGPath);
    CGContextAddPath(context,nextPath.CGPath);
    CGContextClip(context);
    CGContextClearRect(context,CGRectMake(0,0,filteredImage.size.width,filteredImage.size.height));

    // Build a new UIImage from the image context.
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

我想要的是使用另一条路径。我怎样才能做到这一点?我尝试像这样创建新的UIBezierPath:UIBezierPath *newPath = [UIBezierPath bezierPath];然后我再次添加CGPoint:

CGPoint mouthTempPoint = CGPointMake(mouthPos.x-30, mouthPos.y-10);

    [newPath addLineToPoint:CGPointMake(mouthTempPoint.x, mouthTempPoint.y)];
    mouthTempPoint = CGPointMake(mouthPos.x+30, mouthPos.y-10);
    [newPath addLineToPoint:CGPointMake(mouthTempPoint.x, mouthTempPoint.y)];
    mouthTempPoint = CGPointMake(mouthPos.x+30, mouthPos.y-30);
    [newPath addLineToPoint:CGPointMake(mouthTempPoint.x, mouthTempPoint.y)];
    mouthTempPoint = CGPointMake(mouthPos.x-30, mouthPos.y-30);
    [newPath addLineToPoint:CGPointMake(mouthTempPoint.x, mouthTempPoint.y)];
    mouthTempPoint = CGPointMake(mouthPos.x-30, mouthPos.y-10);
    [newPath addLineToPoint:CGPointMake(mouthTempPoint.x, mouthTempPoint.y)];

但我得到了一个错误。我的错误是<Error>: void CGPathAddLineToPoint(CGMutablePathRef, const CGAffineTransform *, CGFloat, CGFloat): no current point.

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:1)

查看您在第一个代码部分开始的路径

CGPoint tempPoint = CGPointMake(leftEyePos.x+30,leftEyePos.y-25);
    [currentPath moveToPoint:CGPointMake(tempPoint.x, tempPoint.y)];

要开始换行,您必须拥有起点