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).
Set the drawsAsynchronously
property to YES
. This will queue drawing requests in a background thread instead of drawing in the main thread.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With