2010-05-12 106 views

回答

1

Inside -drawRect:,您使用CGContextAddPath将其添加到上下文中,并使用CGContext(Draw|Fill|Stroke)Path来绘制它。即您子类NSView,并覆盖

- (void)drawRect:(NSRect)needsDisplayInRect 
{ 
    CGContextRef cgcontext = [[NSGraphicsContext currentContext] graphicsPort]; 
    CGContextAddPath(cgcontext,path); // assumes you have CGPathRef*path; 
    CGContextStrokePath(cgcontext); 
} 

然后-drawRect:将在适当时调用。您可以通过调用[view displayIfNeeded]来强制更新视图。

+1

CGContextAddPath实际上并没有绘制路径 - 您需要使用CGContext {Draw | Fill | Stroke}路径。 – Chuck 2010-05-12 18:24:24

+0

Chuck是对的。这就是我最终做的。只是认为会有一个更简单的方法,但我猜不是。 – 2010-05-12 18:34:11

+0

你是对的。我会纠正它。 – Yuji 2010-05-12 18:48:38