Pregunta

Tengo un CGPath y quiero llamar una vez a un NSView. Parece relativamente simple, no he encontrado una manera de AppKit (no iPhone).

¿Fue útil?

Solución

Dentro de -drawRect:, se utiliza CGContextAddPath para añadirlo a un contexto, y CGContext(Draw|Fill|Stroke)Path uso para dibujar ella. Es decir. que subclase NSView y anulación

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

A continuación, -drawRect: se llamará siempre que sea apropiado. Puede forzar la vista para la actualización llamando [view displayIfNeeded].

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top