0
我制作了一个图像编辑应用程序。所以我想用户填写uiview的颜色,用户用手指触摸擦除颜色。 我使用手指清除UIImageView的代码,但是如何清除uiview的颜色。用手指清除UIView的背景色
我要让喜欢PicsArt不仅的纸效果。(PicsArt不仅在App商店) 请帮我...
- (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];
}
我想清除视图的背景颜色..请帮助..如何画这个.. – 2014-12-06 05:44:42
[[UIColor clearColor] setFill]; CGContextFillRect(context,rect); – x4snowman 2014-12-06 07:10:13
在您继续编写代码之前,您可以参考Quartz 2D Programming Guide,它可以帮助您了解绘图系统。 https://developer.apple.com/library/mac/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/Introduction/Introduction.html – x4snowman 2014-12-06 07:11:40