I have a view that has a background image and a CGPath
that gets changed as the user touches the screen. Drawing the image with CGContextDrawImage()
and then drawing the path on top is not fast enough and it hinders the touch event performance. What I would like to have is to have a bitmap buffer and only draw the changes in the path to it. Thus, the view's drawRect()
will be just drawing the buffer. I suspect I will need to use CGContext
s but I can't quite figure out how to do it. Is there a different way of optimizing this?
Edit:
I am adding to the path every time the user touches the screen; so the "path changes" refers to adding more points to an existing path. This is why I think I can just buffer the image and draw just the "delta" of the path instead of drawing the whole thing each time. At the moment my drawing and event logic are something like this:
-(void)drawRect{
//Draw the background image
//Draw the whole path
}
-(void)touchesMoved{
//Add the touch point to the path
[self setNeedsDisplay];
}
Drawing the background this way makes touch event sampling perform noticeably worse than drawing just the path.