Graphics Reference
In-Depth Information
View Resizing
Views can be resized the same as windows can, but the keypath you use differs. You can
call -setFrame on a view using the same code you used for a window, as shown in
Listing 3-3.
LISTING 3-3
Animate View Frame Change in an NSAnimationContext
[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext ] setDuration :5.0f];
[[view animator] setFrame:newFrame display: YES ];
[NSAnimationContext endGrouping];
The only difference between this code and the code in Listing 3-1 is the object we're
calling -setFrame on—a view in this case.
If you want to use explicit animation, instead of animating the frame, animate the
frameOrigin and the frameSize . Listing 3-4 shows how to animate both of these
properties.
LISTING 3-4
Explicitly Animating Frame Origin and Size
CABasicAnimation *originAnimation = [ CABasicAnimation
animationWithKeyPath : @”frameOrigin” ];
[originAnimation setFromValue :[ NSValue
valueWithPoint:oldImageFrame.origin]];
[originAnimation setToValue:[ NSValue valueWithPoint:newFrame.origin]];
[originAnimation setDuration :5.0];
CABasicAnimation *sizeAnimation = [ CABasicAnimation
animationWithKeyPath : @”frameSize” ];
[sizeAnimation setFromValue :
[ NSValue valueWithSize:oldImageFrame. size ]];
[sizeAnimation setToValue:[ NSValue valueWithSize:newFrame. size ]];
[sizeAnimation setDuration :5.0];
[[view animator] setAnimations :[ NSDictionary
dictionaryWithObjectsAndKeys :originAnimation,
@”frameOrigin” ,
sizeAnimation,
@”frameSize” ,
nil ]];
[[view animator] setFrame :newFrame];
 
Search WWH ::




Custom Search