如何擦除子视图中的行 [英] How to erase lines in a subview
本文介绍了如何擦除子视图中的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一款可以在照片上画线的照片应用。
背景是照片,通过画画我在子视图上绘制线条。
I'm working on an photo app where you can draw lines on an photo. The background is the photo, and via drawrect I draw lines on a subview.
每件事情都有效但是如何擦除子视图上的线条(如橡皮擦),我尝试使用clearColor作为setStroke。
Every thing works but how can I erase lines on a subview (like an eraser), I tried with clearColor as setStroke.
是否可以删除这样的行。
Is it possible to erase the lines like this.
推荐答案
@omz给出的响应的实现可能是:
(假设 imgBlank
是 UIImageView
放置在viewcontroller的主视图之上)
An implementation of the response given by @omz could be:
(assuming imgBlank
is a UIImageView
placed on top of the main view of the viewcontroller)
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:self.imgBlank];
NSValue *valCurrPoint=[NSValue valueWithCGPoint:CGPointMake(currentPoint.x, currentPoint.y)];
[self.dots addObject:valCurrPoint];
[self performSelector:@selector(draw:) withObject:valCurrPoint afterDelay:0];
}
-(void)draw:(NSValue*)pointz{
CGPoint point=[pointz CGPointValue];
UIGraphicsBeginImageContextWithOptions(self.imgBlank.frame.size,NO,0);
[self.imgBlank.image drawInRect:CGRectMake(0, 0, self.imgBlank.frame.size.width, self.imgBlank.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(),tickness);//set the tickness here
CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeClear);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0f, 1.0f, 1.0f, 1.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextSetShouldAntialias(UIGraphicsGetCurrentContext(), YES);
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), _lastPoint.x, _lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), point.x, point.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
self.imgBlank.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
_lastPoint = point;
}
这篇关于如何擦除子视图中的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文