1
votes

I have a UIView that allows the user to draw a line (myLine) on the screen. This UIView is directly above another UIView that has several shapes drawn with CGPaths. When the user taps on one of these shapes I need to erase any portion of myLine that is above one of these other shapes as if I was erasing the pixels with an eraser. What would be the best way to approach this?

enter image description here

I need the light blue part of the line to be erased leaving the dark blue portion

1) (current approach partially works) I'm able to use the path shape from the bottom view as a mask in the top view but it is only masking the UIView. If I later need to change the mask location the vector strokes are still there. (I know this is because all off my lines are being redrawn in the drawrect of the view)

2) After I draw each line should I somehow cache the drawing as an image and THEN slice out the parts inside the triangle?

3)Is there a better approach to this?

1

1 Answers

0
votes

This link provided the answer: Building a Simple Drawing App

I cache the drawing to a bitmap context and then clip out the unneeded parts of the bitmap.