Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CALayer drawing in background

I have to do a large and complicated drawing in an iOS app. The drawing area also has to be scrollable and zoomable. I implemented this by splitting the drawing area into many small CALayers as tiles. Whenever the user scrolls the drawing area by some amount, tiles from the invisible area are moved to the other side and new content is drawn inside. Each CALayer has a drawing delegate and only the tiles that are moved get the setNeedsDisplay call.

In fact, I somehow mimic the behaviour of CATiledLayer, which I cannot use directly because I need more control and flexibility than this provides.

My code works nicely so far, but on complex drawings, there are still hickups in the UI while the content is redrawn during scrolling. I hoped that the drawing would be completely in the background, but the UI thread seems to block during drawing.

Is there a way to make iOS call the CALayer's drawing delegate asynchronously in the background? I actually do not mind if the drawing shows up a bit delayed (since the tile will appear outside the visible area anyways).

like image 270
farindk Avatar asked Feb 14 '14 16:02

farindk


1 Answers

Set the drawsAsynchronously property to YES. This will queue drawing requests in a background thread instead of drawing in the main thread.

like image 123
Krumelur Avatar answered Oct 14 '22 17:10

Krumelur