Graphics Reference
In-Depth Information
LISTING 13-12
Continued
[[ self layer] setBackgroundColor:color];
[UIView commitAnimations];
}
Using this method, we first determine the delta of the current UITouch based on the
touchBeganPoint . If the x or y delta is greater than the tap threshold, the touch is treated
as the end of a move and resets the state. If the touch is within the tap threshold,
however, we need to change the background color of the view and cause it to throb for
visual feedback.
After rotating the color index and grabbing a reference for the next color, we begin an
animation block. This tells the iPhone OS that all the property changes within this block
should be performed together as a single animation transaction. We then set ourselves as
the delegate for the animation. Because we want the transform to reverse, we need to add
another transform to the delegate call. This enables us to reset the scale back to normal
after the initial zoom as completed.
After setting the delegate, we give it an @selector to call back on when the animation is
complete. Finally, we apply the grow transform, set the background color, and commit
the animations. This now causes the view to expand by 40 percent and change its back-
ground color in a smooth animation. After this animation block is complete, we need to
apply another transform with the -throbReset: context: method to undo the grow
transform, as shown in Listing 13-13.
LISTING 13-13
-throbAnimationDidStop:finished:context: Implementation
- ( void )throbReset:(NSString*)animationID
context:( void *)context
{
[UIView beginAnimations: nil context: NULL ];
[UIView setAnimationDuration:0.15];
[ self setTransform:CGAffineTransformMakeScale(1.1, 1.1)];
[UIView commitAnimations];
}
Another animation block is created within this method. Its duration is set to be the same
as the previous animation, and it applies another transform to the view to reduce its size
back down before committing the animation.
Finally, we need to implement the -touchesMoved:withEvents: method, which is respon-
sible for animating the view's move and for updating the state information so any subse-
quent moves are handled correctly. See Listing 13-14.
 
Search WWH ::




Custom Search