0
votes

I have implemented drawing line on UIView( it's background is transparent.) using UIBezierPath.

For drawing line, I have used following code in - (void)drawRect:(CGRect)rect method:-

UIBezierPath *_path = [pathArray objectAtIndex:0];
[currentColor setStroke];
[_path strokeWithBlendMode:kCGBlendModeNormal alpha:1.0];

Here pathArray is array of multiple UIBezierPath objects.

For erasing draw, I have used following code in - (void)drawRect:(CGRect)rect method:-

UIBezierPath *_path = [pathArray objectAtIndex:10];
[[UIColor clearColor] setStroke];
[_path strokeWithBlendMode:kCGBlendModeClear alpha:1.0];

Above both method working well while drawing on transparent UIView. But while i am drawing on UIView with white background color, there is black color appeared where i have erased draw. Also same problem appeared while capture screenshot of drawing view. Any solution?

See following screenshots of same drawing, you will get it clear.

1

1 Answers

1
votes

I have solved problem by myself. I have write code for erasing drawing like as:

UIBezierPath *_path = [pathArray objectAtIndex:10];
[drawingView.backgroundColor setStroke];
[_path strokeWithBlendMode:kCGBlendModeCopy alpha:1.0];

Here you have to set strokeWithBlendMode to kCGBlendModeCopy instead of kCGBlendModeClear and use background color of view on which you are drawing.