small medium large xlarge

Generic-user-small
13 Sep 2010, 17:47
Greg Wyder (1 post)

Please help me understand how the drawing works in First Animation. I am relatively new to Cocoa, but I’ve worked through several books (including Steinberg’s excellent Cocoa Programming), and several other tutorials, including several that subclass NSView. In every one of them the screen drawing is accomplished by drawRect and setNeedsDisplay. First Animation uses neither (as far as I can see).

The “Moving the Image” section on page 12 seems to say that the drawing is accomplished directly or indirectly by setFrame. But the Xcode documentation for the setFrame method of NSView says this: “This method, in setting the frame rectangle, repositions and resizes the receiver within the coordinate system of its superview. It neither redisplays the receiver nor marks it as needing display. You must do this yourself with display or setNeedsDisplay:.”

And the View Programming Guide says this: “None of the methods that alter a view’s frame rectangle automatically redisplay the view or marks it as needing display. When using the setFrame… methods, you must mark both the view being repositioned and its superview as needing display”

However, I put NSLogs before and after the setFrame statements, and setFrame clearly does set needsDisplay (or indirectly causes it to be set), for both subview “mover” and superview “self” (BaseView). But without a drawRect, what does the drawing?

So I’m very confused as to how First Animation draws the views. Could you please explain? Thanks!

Biopic_100x100_pragsmall
17 Oct 2010, 05:07
Bill Dudney (917 posts)

Hi Greg,

Sorry to be so late getting back to you!

The secret to Core Animation is that drawing is not required to be done. So when you call setFrame: on a view (whose superview is layer backed) no drawing needs to be done to have that view move to the new location.

Hope this helps, please post back if it is still an issue.

You must be logged in to comment