質問

CGPath があり、それを NSView に一度描画したいと考えています。比較的簡単に思えますが、AppKit(iPhone以外)では方法が見つかりませんでした。

役に立ちましたか?

解決

内部 -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].

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top