How can I erase UIBezierPath lines drawn on a tran

2019-01-24 23:21发布

I am creating an app like whiteboard application. I have one dynamic image. Image has multiple colors. I want to draw line on that Image same as whiteboard so I had overlap a Transparent View on that. Now I am drawing line with chosen color that's working very well.

Now the problem is when I try to erase the line when touch on screen it should show effects like eraser. If I has some fixed color (like white) background then for erasing line I can draw a line with background color but here I have transparent background of view so I cant do that.

I tried with draw a line with color has alpha = 0 but this doesn't reflect anything as the line is also transparent color.

I am adding in my draw rect method.

for (UIBezierPath *path in aryDrawPath) {       
    [[UIColor redColor] set];       
    [path stroke];
}

Can any body help me to solve this problem.

Thanks a lot

2条回答
beautiful°
2楼-- · 2019-01-25 00:01

If you have an image in the background, and the image is the same size and origin as your whiteboard drawing canvas, you could try drawing your "erase" lines using the background image as a colour pattern:

[[UIColor colorWithPatternImage:backgroundImage] set];

Where backgroundImage is the UIImage that you are drawing on top of.

This will overpaint your drawn lines with the image underneath, so it will appear that they are erased. It seems a bit hacky, though?

查看更多
做个烂人
3楼-- · 2019-01-25 00:01

You can use blend mode. Use CGBlendMode..Clear Document

查看更多
登录 后发表回答