我有一个CGPath和我想提请它一旦到NSView.似乎相对简单但是我还没有找到一种方法在AppKit(非iphone).

有帮助吗?

解决方案

内部 -drawRect:, 你使用 CGContextAddPath 添加这一背景下,并使用 CGContext(Draw|Fill|Stroke)Path 绘制它。I.e。你的子类NSView,并复盖

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

然后 -drawRect: 将被称为每当合适的。你可以力图通过调用更新 [view displayIfNeeded].

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top