Graphics Reference
In-Depth Information
set the view frame, for example, you instead call [[view animator] setFrame:newFrame] .
The difference is that we have instructed the view's animator proxy object to set the prop-
erty for us—which implicitly animates the value from the current value to the value
specified in newFrame .
The Animation Proxy Object
So what is the animator proxy object? The animator proxy object is available in both
NSView and NSWindow . It implements the protocol NSAnimatablePropertyContainer . This
container uses Key-Value Coding to set the actual value of whatever parameter was speci-
fied while doing the value interpolation and animation behind the scenes.
As the name implies, the animator proxy acts as an agent that takes the value you give it
and handles animating the property from the starting or current value to the value speci-
fied. It then sets the property as if you had called set on the property explicitly.
The Differences Between Window, View, and
Layer Animation
The idea behind animation in windows, views, and layers is the same; however, the
implementation differs. In this section, we discuss one of the most common animations
you will likely want to implement—frame resizing.
Window Resizing
Since the first version of Mac OS X, the ability to animate a window's frame has been
available to developers in the method -(void)setFrame:(NSRect)windowFrame
display:(BOOL)displayViews animate:(BOOL)performAnimation . The first parameter is
the new frame you are animating to. The second parameter tells the window to call
-displayIfNeeded on all of its subviews,
and the third parameter tells the
window to animate the transition from
its current frame to the frame specified
in the first parameter. If this last para-
meter is set to NO , the change to the new
frame happens immediately rather than
progressively with animation.
NOTE
This call is different than what you use for
changing the frame in both NSView s and
CALayer s. They both have a method called
-setFrame . We discuss that more in
moment.
With this built-in window frame resizing capability, why would you need to use Core
Animation for changing a window's frame? The answer is, simply, you don't. For many
cases when resizing, you can use the built-in functionality and you probably should.
There may be times, however, when you want more control over animating windows.
Keep several things in mind when doing so. NSWindow has an animator proxy just like
NSView . When you call the animator, it animates the parameter you specified, but the
 
 
Search WWH ::




Custom Search