如何用png-brush和UIBezierPath擦除UIImageView片段 [英] How to erase piece of UIImageView with png-brush and UIBezierPath
问题描述
我有两个UIImageView,第一个超过第二个。我想用画笔擦掉第一张图片的一部分(画笔是带有柔和边缘的png图片),以使第二张图片的一部分可见。
我这样做了方式:
1) touchesMoved 和 [self setNeedsDisplayInRect:[self brushRectForPoint:touch_location]];
2)在(void)drawRect:(CGRect)rect 我调用 [_ brush drawAtPoint:touch_location blendMode:kCGBlendModeDestinationOut alpha:1];
它运作正常,但 touchesMoved 的频率不够,如果用户移动手指太快,我会得到很多短线(或甚至点)而不是一条长线。
我找到了UIBezierPath和将会很有趣。
希望有所帮助!
I have two UIImageView, first above second. I want to erase piece of the first image with brush (brush is a png picture with soft edge) to make piece of the second image visible.
I did that by this way:
1) touchesMoved and [self setNeedsDisplayInRect:[self brushRectForPoint:touch_location]];
2) at (void)drawRect:(CGRect)rect I call [_brush drawAtPoint:touch_location blendMode:kCGBlendModeDestinationOut alpha:1];
It works ok, but frequency of touchesMoved not enough, if user moves finger too fast then I get a lot of short lines (or even points) instead of one long line.
I found information of UIBezierPath and example but author just draws lines by path:
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextAddPath(context, path);
CGContextSetLineCap(context, kCGLineCapRound);
CGContextSetLineWidth(context, self.lineWidth);
CGContextSetStrokeColorWithColor(context, self.lineColor.CGColor);
CGContextStrokePath(context);
How I can draw my png brush with UIBezierPath?
I need something like this
Thanks a lot!
There is an open source project which will be useful for you .. iOS-Scratch-n-See. Class ImageMaskView
will be interesting to study.
Hope that helps!
这篇关于如何用png-brush和UIBezierPath擦除UIImageView片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!