views:

154

answers:

2

I made a nice UIView subclass which paints all its stuff in -drawRect:, because people said that's good. That view is a subview of another. This another view is beeing animated with Core Animation: It's scaled down, rotated and moved. However, I encountered this: -drawRect seems to get called trillion of times during animation, and performance sucks.

Is that normal or did I do something wrong, probably?

And I have found this in the documentation of UITableViewCell, which is strange:

However, drawing in editing mode is not encouraged because, as you might recall, custom drawing while cells animate into and out of editing mode severely affects performance.

So -drawRect: is very very bad when doing any core animation thing? I also remember from some other apple resource, that they "don't redraw during animation". Paradoxon. Again.

+1  A: 

drawRect: should only be called after setNeedsDisplay: YES is called on your view. I'm guessing that as the scaling is happening your view is being asked to redraw. If the scaling, rotating, and moving is part of a transition you may be able to perform the transition on a cached view.

jessecurry
A: 

If your UIView's contentMode is set to UIViewContentModeRedraw then, according to the documentation setNeedsDisplay will be called whenever the bounds change. I'm not sure if this would be true during animation, however (I was under the impression the animation system behaved differently) but could explain the flurry of calls to drawRect.

fbrereto