I am drawing many audio meters on a view and finding that drawRect can not keep up with the speed of the audio change. In practice only a very small part of the image changes at a time so I really only want to draw the incremental changes.
I have created a CGLayer
and when the data changes I use CGContextBeginPath
, CGContextMoveToPoint
, CGContextAddLineToPoint
and CGContextStrokePath
to draw in the CGLayer.
In drawRect
in the view I use CGContextDrawLayerAtPoint
to display the layer.
When the data changes I draw just the difference by drawing a line over the top in the CGLayer
. I had assumed it was like photoshop and the new data just draws over the old but I now believe that all the lines I have ever drawn remain present in the layer. Is that correct?
If so is there a way to remove lines from a CGLayer
?