Graphics Reference
In-Depth Information
LISTING 13-11
-touchesCancelled:withEvent: Implementation
- ( void )touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
touchBeganPoint = CGPointZero;
lastUpdatedPoint = CGPointZero;
}
A cancel event occurs only when something interrupts the application. For example, this
might happen when there is an incoming SMS message, phone call, or some other exter-
nal event on the iPhone. As such, don't treat a cancel as a failure but as an opportunity to
reset the state.
If the event is not canceled, you can send either of the following two methods next:
-touchesEnded:withEvent: or -touchesMoved:withEvent: . For this application, we
implement -touchesEnded:withEvent: , as shown in Listing 13-12.
LISTING 13-12
-touchesEnded:withEvent: Implementation
- ( void )touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint touchPoint = [[touches anyObject] locationInView:[ self window]];
float deltaX = touchPoint.x - touchBeganPoint .x;
float deltaY = touchPoint.y - touchBeganPoint .y;
touchBeganPoint = CGPointZero;
lastUpdatedPoint = CGPointZero;
touchBeganPoint = CGPointZero;
lastUpdatedPoint = CGPointZero;
if (deltaX > MAX_TAP_DELTA && deltaY > MAX_TAP_DELTA ) {
return ;
}
++ colorIndex ;
if ( colorIndex >= [ colorArray count]) colorIndex = 0;
CGColorRef color = [[ colorArray objectAtIndex: colorIndex ] CGColor];
[UIView beginAnimations: nil context: NULL ];
[UIView setAnimationDelegate: self ];
[UIView setAnimationDuration:0.15f];
[UIView setAnimationDidStopSelector: @selector ( throbReset : context :)];
[ self setTransform:CGAffineTransformMakeScale(1.4, 1.4)];
 
Search WWH ::




Custom Search