How to remove part of UIImageView using png-brush and UIBezierPath

I have two UIImageView, first the second. I want to remove part of the first image with a brush (the brush is a png image with a soft edge) to make part of the second image visible.

I did it as follows:

1) touchhesMoved and [self setNeedsDisplayInRect: [self brushRectForPoint: touch_location]];

2) in (void) drawRect: (CGRect) rect I call [_ brush drawAtPoint: touch_location blendMode: kCGBlendModeDestinationOut alpha: 1];

It works fine, but the frequency of touchhesMoved is not enough, if the user moves the finger too fast, then I get a lot of short lines (or even dots) instead of one long line.

I found information about UIBezierPath and an example , but the author just draws the lines along the path:

CGContextRef context = UIGraphicsGetCurrentContext(); CGContextAddPath(context, path); CGContextSetLineCap(context, kCGLineCapRound); CGContextSetLineWidth(context, self.lineWidth); CGContextSetStrokeColorWithColor(context, self.lineColor.CGColor); CGContextStrokePath(context); 

How can I paint my png brush using UIBezierPath?

I need something like this

enter image description here

Thanks a lot!

+6
source share
1 answer

There is an open source project that will be of use to you. iOS-Scratch-n-See . The ImageMaskView class will be interesting to learn.

Hope this helps!

+1
source

Source: https://habr.com/ru/post/949554/


All Articles