使用 UIBezierPath 擦除线条图

发布于 2024-11-11 07:00:50 字数 91 浏览 0 评论 0原文

使用 UIBezierPath 做了一个简单的线条绘制应用程序,但现在需要一种方法来擦除用 UIBezierPath 绘制的线条。有没有办法实现橡皮擦功能来删除线条画?

Did a simple application for line drawing with UIBezierPath, but now need a way to erase the line drawn with UIBezierPath. Is there a way to implement eraser feature for removing the line painting?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

唐婉 2024-11-18 07:00:50

如果您使用图像作为背景,那么您可以将相同的图像设置为画笔图案来绘制贝塞尔路径,它实际上会给您带来橡皮擦效果。这对我有用。 :)

    brushPattern=[[UIColor alloc]initWithPatternImage:[UIImage imageNamed:@"image.jpg"]];
    // Here image.jpg is you background image

If you are using an image as background then you can set the same image as brush pattern to draw the bezierpath it will virtually give you the eraser effect. It works for me. :)

    brushPattern=[[UIColor alloc]initWithPatternImage:[UIImage imageNamed:@"image.jpg"]];
    // Here image.jpg is you background image
以为你会在 2024-11-18 07:00:50
if(erase)
{
    [myPath strokeWithBlendMode:kCGBlendModeClear alpha:1.0f];
}
else
{
    [myPath strokeWithBlendMode:kCGBlendModeNormal alpha:1.0f];
}
if(erase)
{
    [myPath strokeWithBlendMode:kCGBlendModeClear alpha:1.0f];
}
else
{
    [myPath strokeWithBlendMode:kCGBlendModeNormal alpha:1.0f];
}
迟月 2024-11-18 07:00:50

橡皮擦可以有效地在迄今为止绘制的每条路径上绘制一条与背景颜色相同的线。您可能需要注意,它是某处的橡皮擦线,以便您可以在背景颜色发生变化时更新橡皮擦线的描边颜色,否则您会失去擦除的错觉。

An eraser effectively draws a line that's the same color as the background atop every path that's been drawn thus far. You might need to note that it's an eraser line somewhere so that you can update the eraser line's stroke color if the background color changes, otherwise you lose the illusion of erasure.

初熏 2024-11-18 07:00:50

根据您对杰里米答案的评论,您似乎正在尝试做虚线。您是否尝试过使用 setLineDash:count:phase:

UIBezierPath *path = [UIBezierPath new];
CGFloat dashArray[3];
dashArray[0] = 8;
dashArray[1] = 3;
dashArray[2] = 8;
[path setLineDash:dashArray count:dashCount phase: 0.0];

Apple 有示例代码这里: http://developer.apple.com/library/ mac/#samplecode/BezierPathLab/Introduction/Intro.html

Based on your comments on Jeremy's answer, it seems like you're trying to do dashed lines. Have you tried using setLineDash:count:phase:

UIBezierPath *path = [UIBezierPath new];
CGFloat dashArray[3];
dashArray[0] = 8;
dashArray[1] = 3;
dashArray[2] = 8;
[path setLineDash:dashArray count:dashCount phase: 0.0];

Apple has sample code here: http://developer.apple.com/library/mac/#samplecode/BezierPathLab/Introduction/Intro.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文