I have a custom view which has a piano keyboard drawn inside of it. Each key is drawn as a separate call, so that I can only draw keys that need redrawing. The view supports multiple touch, so multiple keys can be held down at once.
Each key is somewhat expensive to draw, so I pass a specific region to setNeedsDisplay whenever a touch is detected on the view in order to avoid re-drawing the entire view (which produces noticeable lag).
In order to handle multiple touches, I iterate over the set of received touches, check if each touch is within one of the keys, and if so, update it and call setNeedsDisplay with the rectangle of that key. In short, setNeedsDisplay is called multiple times in one function, but with a different rect each time.
The behavior that I expected was that drawRect would be invoked multiple times with different dirty regions, however, it seems that if I press the far left and far right keys at the same time, the entire view is redrawn, rather than just the far left and far right keys (as in, all the keys in between are redrawn unnecessarily).
What can I do to achieve what I want? I want to just draw the keys that are touched, not all the keys in between the two dirty keys.