是否可以删除由路径中的区域NSBezierPath
定义的一部分?NSRect
问问题
2880 次
2 回答
10
正如评论中指出的那样,Caswell 先生的回答实际上与 OP 所要求的相反。此代码示例显示如何从圆(或任何其他贝塞尔路径中的任何贝塞尔路径)中删除矩形。诀窍是“反转”要删除的路径,然后将其附加到原始路径:
NSBezierPath *circlePath = [NSBezierPath bezierPathWithOvalInRect:NSMakeRect(0, 0, 100, 100)];
NSBezierPath *rectPath = [NSBezierPath bezierPathWithRect:NSMakeRect(25, 25, 50, 50)];
rectPath = [rectPath bezierPathByReversingPath];
[circlePath appendBezierPath:rectPath];
注意:如果贝塞尔路径相互交叉,事情会变得有点棘手。然后你必须设置正确的“缠绕规则”。
于 2013-07-13T00:07:28.307 回答
5
绝对地。这就是裁剪区域的作用:
// Save the current clipping region
[NSGraphicsContext saveGraphicsState];
NSRect dontDrawThisRect = NSMakeRect(x, y, w, h);
// Either:
NSRectClip(dontDrawThisRect);
// Or (usually for more complex shapes):
//[[NSBezierPath bezierPathWithRect:dontDrawThisRect] addClip];
[myBezierPath fill]; // or stroke, or whatever you do
// Restore the clipping region for further drawing
[NSGraphicsContext restoreGraphicsState];
于 2011-04-15T23:17:56.873 回答