My iPad application uses a UIScrollView in which I've implemented the drawRect: method. This method updates only the portion of the view that needs to be redrawn. The content that needs to be drawn changes upon some gesture by the user (like in a drawing app). During a gesture, the setNeedsDisplayInRect: method of the scrollview is called with the rect that needs to be redrawn.
This usually all works fine and as expected. However, if the user starts a new gesture after a period of inactivity (~10 seconds), then the drawRect: method gets called 3 times with a rect-parameter that is of the size of the screen (the currently visible part of the scrollview). This leads to a noticeable loss in the frame rate of the gesture recognizer.
I don't know why the drawRect: method gets called 3 times with the fullscreen rect. I've tried to detect these "needless" calls to drawRect and just do nothing. However, this leads to a cleared screen (changing clearsContextBeforeDrawing did not help). I've also tried to change the scrollview's contentMode property. This had no effect on the behavior.
Note that the scrollViewDidScroll: method does never get called during the gesture.
I'm already caching what needs to be drawn in a separate CGImage. However, just copying this image 3 times already has a huge performance hit.
Is there any way to prevent the drawRect: method from being called 3 times? Ideally it should only be called with the small rect to update, but at this point I would already be grateful if it would be called only once with the full rect.