0
我正在使用Matt Gemmell的NSBezierPath + StrokeExtensions类别在NSRect上绘制一个内部描边。这里是整个类别代码:Matt Gemmell的NSBezierPath + StrokeExtensions在剪辑矩形之外绘制
- (void)strokeInside
{
/* Stroke within path using no additional clipping rectangle. */
[self strokeInsideWithinRect:NSZeroRect];
}
- (void)strokeInsideWithinRect:(NSRect)clipRect
{
NSGraphicsContext *thisContext = [NSGraphicsContext currentContext];
float lineWidth = [self lineWidth];
/* Save the current graphics context. */
[thisContext saveGraphicsState];
/* Double the stroke width, since -stroke centers strokes on paths. */
[self setLineWidth:(lineWidth * 2.0)];
/* Clip drawing to this path; draw nothing outwith the path. */
[self setClip];
/* Further clip drawing to clipRect, usually the view's frame. */
if (clipRect.size.width > 0.0 && clipRect.size.height > 0.0) {
[NSBezierPath clipRect:clipRect];
}
/* Stroke the path. */
[self stroke];
/* Restore the previous graphics context. */
[thisContext restoreGraphicsState];
[self setLineWidth:lineWidth];
}
这里是我的drawRect:
方法:
- (void)drawRect:(NSRect)dirtyRect {
NSRect myRect = NSMakeRect(500, 0, 400, 100);
[[NSColor colorWithCalibratedRed:0 green:0 blue:1.0 alpha:0.5] set];
NSRectFillUsingOperation(myRect, NSCompositeSourceOver);
[[NSColor blueColor] set];
[[NSBezierPath bezierPathWithRect:myRect] strokeInside];
}
然而,出现这种情况时,我向上滚动:
,你可以看,里面的笔画绘制到工具栏上。为什么会发生?我如何解决strokeInside
方法?请注意,这不会发生在常规的stroke
方法中。