Erase line drawing with UIBezierPath

二次信任 提交于 2020-01-11 06:42:11

问题


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?


回答1:


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



回答2:


if(erase)
{
    [myPath strokeWithBlendMode:kCGBlendModeClear alpha:1.0f];
}
else
{
    [myPath strokeWithBlendMode:kCGBlendModeNormal alpha:1.0f];
}



回答3:


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.




回答4:


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



来源:https://stackoverflow.com/questions/6177490/erase-line-drawing-with-uibezierpath

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!