2

Assume that two very small areas of my view need to be redrawn. One is in the upper left corner, the other in the bottom right. I could use their coordinates to pass a single large CGRect that contains both areas to setNeedsDisplayInRect, but this will end up including a lot of other areas that do not need to be redrawn.

So the other option would be to simply pass their individual containing CGRects to setNeedsDisplayInRect, one after the next, i.e.

[self.view setNeedsDisplayInRect:rectForArea1]
[self.view setNeedsDisplayInRect:rectForArea2]

Which would generally be faster? Minimizing the number of times that drawRect: ultimately gets called, or minimizing the amount of screen area that it has to redraw, even if it must redraw twice?

maxedison
  • 17,243
  • 14
  • 67
  • 114

2 Answers2

3

It does not matter. As described here, iOS will always update the whole view, independent of what rect you pass into setNeedsDisplayInRect:

Note that, because of the way that iPhone/iPod touch/iPad updates its screen, the entire view will be redrawn if you call -setNeedsDisplayInRect: or -setNeedsDisplay:.

fishinear
  • 6,101
  • 3
  • 36
  • 84
0

it is depending upon that two rect.

if both bounds addition are 75% of view bounds then i will call simply call

    [self.view setNeedsDisplay];

because we draw almost whole view.

if both bounds addition are below 50% of view bounds then i will call simply call

    [self.view setNeedsDisplayInRect:rectForArea1];

    [self.view setNeedsDisplayInRect:rectForArea2];

because we need to draw small spaces

  • Can you provide anything to back up these choices? For example, it seems to me that simply calling setNeedsDisplay any time the re-drawing area is over 75% of the screen is a bit lazy. Although the re-drawing is most of the screen, you're still redrawing quite a bit that you don't need to, so it could be made more efficient. And depending on what you have in that last 25% of the screen, that extra re-drawing could be quite expensive. – maxedison Jul 23 '11 at 13:14
  • if u dont care about number of times the needdisplay method calling then go ahead with only draw rect – Vijay-Apple-Dev.blogspot.com Jul 23 '11 at 13:20
  • But I do care. The whole purpose of my post is to find out which is the most efficient way to achieve the same thing. So if calling drawRect: multiple times on different small CGRects is more expensive than calling it once on a large CGRect, i'd prefer to do that. And vice versa. – maxedison Jul 23 '11 at 14:38
  • it depends upon ur app needs. u have to choose – Vijay-Apple-Dev.blogspot.com Jul 23 '11 at 14:44