有谁知道如何在CALayer上绘制透明圆圈,就像使用CGContextClearRect绘制透明矩形一样?我的要求是我需要在图片上绘制一个蒙版,在某些情况下,我需要删除它,但CGContextClearRect只允许绘制一个矩形,我想知道是否有另一种方法可以做同样的事情并绘制一个透明的圆圈
此致 安托
答案 0 :(得分:3)
Shreekara的评论略有偏差。使用AddArc而不是StrokeEllipse:
CGRect cirleRect = CGRectMake(0, 0, 100, 100);
CGContextAddArc(context, 50, 50, 50, 0.0, 2*M_PI, 0);
CGContextClip(context);
CGContextClearRect(context,cirleRect);
答案 1 :(得分:1)
最初绘制圆圈,然后剪切路径,然后再次通过CGContextClearRect清除圆圈的边界矩形。