0

I would like to learn how to create a simple drawing app for iOS. I can get to the point of actually drawing the line with a UIBezierPath. I've created a custom view and I use drawRect: to stroke the UIBezierPaths (it's not the most efficient, because I'm drawing every line every time. Once I get the basics, I'll drill down into more efficient implementations).

My question is this: how do I implement an eraser function? I don't want a simple hack like using a path with a white stroke color; I want a legit erase function. I can't figure out how to do this, and I have searched many resources online for this. Some ideas I've had are hit testing to erase certain points in a line and drawing a special "eraser" line that does some sort of blending to erase other lines. I don't think the latter is possible, and I have no idea how to implement the former, or if it's even possible.

Does anyone have some insight they can share on this?

Halen
  • 456
  • 4
  • 14
  • 1
    How do you want to erase them? By that, I mean what action do you want the user take to erase a particular line? I assume also, that these lines won't necessarily be straight lines. Is that correct? – rdelmar May 29 '15 at 23:16
  • I want there to be an eraser tool. So they can just drag the eraser around and erase whatever they want. I would also like to implement an undo functionality that erases the entire last line drawn. But mainly it's the freeform eraser tool that I want. – Halen May 29 '15 at 23:19
  • I don't think there is any straight forward way to do this with bezier paths, other than using the hack you say you don't want. Unless you save the points yourself as you draw, you don't even have access to the points that make up a UIBezierPath. – rdelmar May 29 '15 at 23:43
  • I'm fine with using something other than UIBezierPath. I was just using as an example. And there has to be a way, because I've seen other apps do it. If you take a look at this one, you'll see what I mean (https://itunes.apple.com/us/app/foxit-mobilepdf-edit-pdf-fill/id507040546?mt=8) When you erase, the path is still rounded at the ends, which wouldn't be possible with that hack. I've been wracking my brain for quite some time, and I just can't figure this one out. – Halen May 29 '15 at 23:46
  • Have look at the question and answer here, http://stackoverflow.com/questions/22131762/ios-core-graphics-how-to-erase-a-drawing, to see if this will do what you want. – rdelmar May 29 '15 at 23:55
  • I'll take a look at that and report back. Thanks! – Halen May 30 '15 at 01:17

0 Answers0