Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
862 views
in Technique[技术] by (71.8m points)

iphone - How can I erase UIBezierPath lines drawn on a transparent view above an image?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...