Domanda

Ho un CGPath e voglio disegnare una volta per un NSView. Sembra relativamente semplice, ma non ho trovato un modo AppKit (non iPhone).

È stato utile?

Soluzione

All'interno -drawRect:, è possibile utilizzare CGContextAddPath per aggiungerlo a un contesto, e l'uso CGContext(Draw|Fill|Stroke)Path a disegnarlo. Cioè si sottoclasse NSView, e di override

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

Poi -drawRect: sarà chiamato ove opportuno. È possibile forzare la visualizzazione di aggiornamento chiamando [view displayIfNeeded].

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top