ios - 如何在同一 View 中使用两条贝塞尔曲线路径?

标签 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.

有人可以帮助我吗?

最佳答案

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

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

要开始新的一行你必须有一个起点

关于ios - 如何在同一 View 中使用两条贝塞尔曲线路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23154229/

相关文章:

ios - BezierPath 和掩蔽

ios - 如何在 CAShapeLayer 上快速循环显示颜色?

ios - 使用 UIBezierPath 绘制圆角

objective-c - 使用与呈现时不同的动画关闭模态视图 Controller

javascript - 来自 Illustrator 的 UIBezierPath,引用坐标问题

ios - 将新设备添加到Xcode自动管理的配置文件中

iphone - 创建带有圆边的自定义加载栏

swift - 如何在 Swift 中不旋转 Sprite 的情况下在曲线中移动 SKSpriteNode

ios - 如何用windows PC调试ios.iphone网站

ios - 核心数据以一对多关系保存在后台