Ios 清除UIView';手指触摸时的背景色

Ios 清除UIView';手指触摸时的背景色,ios,uiview,uiimageview,uigraphicscontext,Ios,Uiview,Uiimageview,Uigraphicscontext,我制作了一个图像编辑应用程序。所以我想按用户填充uiview的颜色,用户用手指触摸来擦除颜色。 我用手指为UIImageView编写了这段代码,但是如何清除uiview颜色 我想制作像PicsArt的纸质效果。(PicsArt在App store上) 请帮帮我 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; lastT

我制作了一个图像编辑应用程序。所以我想按用户填充uiview的颜色,用户用手指触摸来擦除颜色。 我用手指为UIImageView编写了这段代码,但是如何清除uiview颜色

我想制作像PicsArt的纸质效果。(PicsArt在App store上) 请帮帮我

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];

    lastTouch = [touch locationInView:_imageview];}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];

    CGPoint currentTouch = [touch locationInView:_imageview];
    UIGraphicsBeginImageContext(_imageview.frame.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    [_imageview.image drawInRect:CGRectMake(0, 0, _imageview.frame.size.width, _imageview.frame.size.width)];
    CGContextSetLineCap(context, kCGLineCapRound);
   CGContextSetLineWidth(context,10);
   CGContextSetBlendMode(context, kCGBlendModeClear);
   CGContextBeginPath(context);
   CGContextMoveToPoint(context, lastTouch.x, lastTouch.y);
   CGContextAddLineToPoint(context, currentTouch.x, currentTouch.y);
   CGContextStrokePath(context);
  _imageview.image= UIGraphicsGetImageFromCurrentImageContext();

  UIGraphicsEndImageContext();

  lastTouch = [touch locationInView:_imageview];}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{


 UITouch *touch = [touches anyObject];
CGPoint currentTouch = [touch locationInView:_imageview];
UIGraphicsBeginImageContext(_imageview.frame.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[_imageview.image drawInRect:CGRectMake(0, 0, _imageview.frame.size.width, _imageview.frame.size.width)];
CGContextSetLineCap(context, kCGLineCapRound);
CGContextSetLineWidth(context,10);
CGContextSetBlendMode(context, kCGBlendModeClear);
CGContextBeginPath(context);
CGContextMoveToPoint(context, lastTouch.x, lastTouch.y);
CGContextAddLineToPoint(context, currentTouch.x, currentTouch.y);
CGContextStrokePath(context);
_imageview.image= UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

lastTouch = [touch locationInView:_imageview];
}


@米兰·帕特尔。您的代码副本,其中包含一些更新。

[[UIColor clearColor]setFill];CGContextFillRect(上下文,rect);在继续编写代码之前,可以参考Quartz 2D编程指南,该指南有助于您理解图形系统。你知道我的问题到底是什么吗?我想创建一个像PicsArt应用程序一样的纸面效果。。
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];

    lastTouch = [touch locationInView:_imageview];}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];

    CGPoint currentTouch = [touch locationInView:_imageview];


    lastTouch = [touch locationInView:_imageview];
    //redraw the view
    [self setNeedsDisplay];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{


    lastTouch = [touch locationInView:_imageview];
    //redraw your view
    [self setNeedsDisplay];
}

- (void)drawRect:(CGRect)rect
{
//Put your draw code here;

//    UIGraphicsBeginImageContext(_imageview.frame.size);
//    CGContextRef context = UIGraphicsGetCurrentContext();
//    [_imageview.image drawInRect:CGRectMake(0, 0, _imageview.frame.size.width, _imageview.frame.size.width)];
//    CGContextSetLineCap(context, kCGLineCapRound);
//    CGContextSetLineWidth(context,10);
//    CGContextSetBlendMode(context, kCGBlendModeClear);
//    CGContextBeginPath(context);
//    CGContextMoveToPoint(context, lastTouch.x, lastTouch.y);
//    CGContextAddLineToPoint(context, currentTouch.x, currentTouch.y);
//    CGContextStrokePath(context);
//    _imageview.image= UIGraphicsGetImageFromCurrentImageContext();
//    
//    UIGraphicsEndImageContext();
}