我正在处理需求,我需要在UIImageView上绘制线条以及触摸点。我需要在按钮点击时清除UIImageView中的所有图纸。我能够绘制线条,但无法在按钮点击时清除线条。我甚至想要实现清除所有和撤消选项。有人请指导我的方式,我可以实现清除所有和撤消选项。下面是我用来实现绘图的代码。不确定如何实现全部清除和撤消绘图。
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:_selectedImageView];
_ctx = UIGraphicsGetCurrentContext();
CGContextSaveGState(_ctx);
UIGraphicsBeginImageContext(self.view.frame.size);
[self.selectedImageView.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), brush );
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), red, green, blue, 1.0);
CGContextSetBlendMode(UIGraphicsGetCurrentContext(),kCGBlendModeNormal);
CGContextStrokePath(UIGraphicsGetCurrentContext());
self.selectedImageView.image = UIGraphicsGetImageFromCurrentImageContext();
[self.selectedImageView setAlpha:opacity];
UIGraphicsEndImageContext();
lastPoint = currentPoint;
答案 0 :(得分:0)
我能够得到我的问题的解决方案,以清除从下面的示例中绘制的点或线。通过从github下面的示例,我能够实现clear all和undo。 https://github.com/backslash112/paint-with-undo/tree/master