开发者

Erase line drawing with UIBezierPath

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?


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


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


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜