Search code examples
cocoansviewclipnsbezierpath

NSBezierPath: how to invert the clip path?


I am drawing a rounded image in the centre of my custom view by creating a rounded NSBezierPath and adding it to the clipping region of the graphics context. This is working well, but I'm wondering if I can improve the performance of drawing the background of the view (the area outside of the rounded centred image) but inverting this clip and performing the background draw (an NSGradient fill).

Can anyone suggest a method of inverting a clip path?


Solution

  • You won't improve the drawing performance of the background by doing this. If anything, using a more complex clipping path will slow down drawing.

    If you want to draw objects over a background without significant overhead of redrawing the background, you could use Core Animation layers as I explained in my answer to this question.