Я делаю приложение для редактирования изображений. Итак, я хочу заполнить цвет 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];
}