tags:

views:

89

answers:

1

When programming my app, I get to the point where I have to update two rectangles on the screen. So I call [self setNeedsDisplayInRect:rect1] and then [self setNeedsDisplayInRect:rect2]. When my drawRect method is called, the rectangle parameter is the smallest rectangle which contains both rect1 and rect2.

I can handle this with no problem, but when the two rectangles are far apart, then I am updating a lot of real estate with no gain. In this case, I would just like to repaint my two small rectangles.

So my question is how can I prevent the underlying system from coalescing my two calls into one?

A: 

You don't have to prevent the system from coalescing the calls because in -drawRect:, you can query the individual regions that have to be updated by calling -getRectsBeingDrawn:count:. This will return your individual rectangles rect1 and rect2.

Note that -getRectsBeingDrawn:count: is guaranteed to return non-overlapping rectangles. This seems to imply that if, for example, you called -setNeedsDisplayInRect: twice for the same rectangle, -getRectsBeingDrawn:count: would only return that rectangle once. In other words, you don't need to worry that you're drawing the same region twice.

Martin B
@Martin: I don't see how to go from a UIView to an NSView. What is the linkage there?
No One in Particular
@No One in Particular: You can't -- `UIView` is the iOS (or rather UIKit) equivalent to Mac OS's (or rather AppKit's) `NSView`. And unfortunately, `UIView` doesn't seem to have `-getRectsBeingDrawn:count:`...
Martin B