Очистить цвет фона UIView на ощупь пальцем

Я делаю приложение для редактирования изображений. Итак, я хочу заполнить цвет uiview пользователем, а пользователь стереть цвет касанием пальца. Я пишу этот код для UIImageView, ясно пальцем, но как очистить цвет uiview.

Я хочу создать эффект бумаги PicsArt (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];
    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];

}


person Milan patel    schedule 05.12.2014    source источник


Ответы (1)


    - (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();
}

@ Милан Пател. Копия вашего кода с некоторыми обновлениями.

person Danyun Liu    schedule 06.12.2014
comment
[[UIColor clearColor] setFill]; CGContextFillRect (контекст, прямоугольник); - person Danyun Liu; 06.12.2014
comment
Прежде чем продолжить код, вы можете обратиться к Руководству по программированию Quartz 2D, которое поможет вам понять систему рисования. developer.apple.com/library/mac/ документация / GraphicsImaging / - person Danyun Liu; 06.12.2014
comment
Вы понимаете, какой у меня вопрос на самом деле или нет. Я хочу создать Paper Effect, как приложение PicsArt .. - person Milan patel; 08.12.2014