我有一个CGPath,我想在NSView中绘制一次。看起来相对简单,但我还没有找到在AppKit (非iphone)中的方法。
发布于 2010-05-13 02:17:23
在-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]来强制更新视图。
https://stackoverflow.com/questions/2821107
复制相似问题