有谁知道如何在CALayer上绘制透明圆形,就像使用CGContextClearRect绘制透明矩形一样?我的要求是我需要在图片上绘制一个蒙版,在某些情况下,我需要删除它,但CGContextClearRect只允许绘制一个矩形,我想知道是否有另一种方法来做同样的事情并画出一个不透明的圆圈。如何绘制像使用CGContextClearRect绘制透明矩形的透明圆形
问候, 安托
有谁知道如何在CALayer上绘制透明圆形,就像使用CGContextClearRect绘制透明矩形一样?我的要求是我需要在图片上绘制一个蒙版,在某些情况下,我需要删除它,但CGContextClearRect只允许绘制一个矩形,我想知道是否有另一种方法来做同样的事情并画出一个不透明的圆圈。如何绘制像使用CGContextClearRect绘制透明矩形的透明圆形
问候, 安托
最初绘制圆圈,然后再剪裁路径,然后再次清除由CGContextClearRect的圆的边界矩形。
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);
这是一种魅力。 – tobyc 2010-06-01 06:44:31
您能否提供一段示例代码?我是Quartz 2d的新手。 – user177946 2009-09-24 07:51:29
CGContextRef context = UIGraphicsGetCurrentContext(); CGRect cirleRect = CGRectMake(0,0,100,100); CGContextStrokeEllipseInRect(context,cirleRect); CGContextClip(context); CGContextClearRect(context,cirleRect); 这将创建一个直径为100像素的透明圆... – Shreekara 2009-09-28 17:58:51