我已经使用 UIBezierPath 在 UIView 上实现了绘图线(它的背景是透明的。)。
对于画线,我在 - (void)drawRect:(CGRect)rect
方法中使用了以下代码:-
UIBezierPath *_path = [pathArray objectAtIndex:0];
[currentColor setStroke];
[_path strokeWithBlendMode:kCGBlendModeNormal alpha:1.0];
这里的 pathArray 是多个 UIBezierPath 对象的数组。
为了删除绘图,我在 - (void)drawRect:(CGRect)rect
方法中使用了以下代码:-
UIBezierPath *_path = [pathArray objectAtIndex:10];
[[UIColor clearColor] setStroke];
[_path strokeWithBlendMode:kCGBlendModeClear alpha:1.0];
在透明 UIView 上绘制时,以上两种方法都运行良好。但是当我在具有白色背景颜色的 UIView 上绘图时,在我删除绘图的地方出现了黑色。捕获绘图 View 的屏幕截图时也出现了同样的问题。有什么解决办法吗?
看下面同一张图的截图,你就明白了。
最佳答案
我自己解决了问题。我已经编写了删除绘图的代码,如下所示:
UIBezierPath *_path = [pathArray objectAtIndex:10];
[drawingView.backgroundColor setStroke];
[_path strokeWithBlendMode:kCGBlendModeCopy alpha:1.0];
在这里,您必须将 strokeWithBlendMode
设置为 kCGBlendModeCopy
而不是 kCGBlendModeClear
并使用您正在绘制的 View 的背景颜色。
关于ios - 删除绘图并捕获 UIView 绘图的屏幕截图无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19047269/