Graphics Reference
In-Depth Information
The implementation file is also quite sparse. Because we do not retain anything, we do
not need a -dealloc method. Likewise, because the controller is named the same as the
xib file, the controller does not need an -init method. Therefore, the controller needs
methods to handle only the user pressing the button and a method to be called when
the animation completes. Start by implementing the -action: method, as shown in
Listing 13-16.
LISTING 13-16
MainViewController.m -action: Implementation
- ( IBAction )action:( id )sender;
{
[ UIView beginAnimations : @”Hide Button” context : nil ];
[[ self button ] setAlpha :0.0];
[ UIView commitAnimations ];
[ UIView beginAnimations : @”Slide Around” context : nil ];
[ UIView setAnimationDuration :1.0];
[ UIView setAnimationDelegate : self ];
[ UIView setAnimationDidStopSelector : @selector ( viewAnimationDone :)];
[ UIView setAnimationRepeatCount :3];
[ UIView setAnimationRepeatAutoreverses : YES ];
CGPoint center = [[ self animImageView ] center ];
center. y += 100;
[[ self animImageView ] setCenter :center];
[ UIView commitAnimations ];
}
This method implements two separate animations. The first fades the button out of
view, and the second moves the UIImageView up and down within its parent.
To perform an animation at the UIView level, we need to first call +beginAnimations:
context: on the UIView class. This tells the view that all the calls following it are to be
animated if possible. This continues until +commitAnimations is called on the UIView .
In the first animation, we have one call within the begin and commit calls, and that sets
the alpha value of the UIView to 0.0 , leaving the duration of the animation set to
default .
The second animation is quite a bit more complicated. Because we want the bounce
to be slower than the default animation, we first set the duration by calling
+setAnimationDuration: and passing it a value of 1.0 . Next, set the view controller as the
delegate for the animation so that it can be notified when the animation is complete. We
 
Search WWH ::




Custom Search