Kri*_*oks 7 cocoa drawing objective-c nsbezierpath
是否有可能删除NSBezierPath由NSRect路径中的某个区域定义的块?
Rob*_*rto 10
正如评论中所指出的,卡斯韦尔先生的回答实际上与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];
Run Code Online (Sandbox Code Playgroud)
注意:如果bezier路径相互交叉,事情会变得有点棘手.然后你必须设置适当的"缠绕规则".
绝对.这是裁剪区域的作用:
// 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];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2715 次 |
| 最近记录: |