//
//  AnimationDelegateAppDelegate.m
//  AnimationDelegate
//
//  Created by Bill Dudney on 7/4/08.
//  Copyright Gala Factory 2008. All rights reserved.
//
//
//  Licensed with the Apache 2.0 License
//  http://apache.org/licenses/LICENSE-2.0
//

#import "AnimationDelegateViewController.h"

@implementation AnimationDelegateViewController

//START:code.delegation.didStart
- (void)didStart:(NSString *)animationId context:(void *)context {
  NSLog(@"started %@", animationId);
}
//END:code.delegation.didStart

//START:code.delegation.didStop
- (void)didStop:(NSString *)animationId finished:(BOOL)flag
        context:(void *)context {
  if(flag) {
    NSLog(@"finished %@", animationId);
  } else {
    NSLog(@"stopped %@", animationId);
  }
}
//END:code.delegation.didStop

//START:code.delegation.touchesEnded
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
  [UIView beginAnimations:@"movement" context:nil]; 
  [UIView setAnimationDelegate:self]; // <label id="code.delegation.setDelegate"/>
  [UIView setAnimationWillStartSelector:@selector(didStart:context:)];
  [UIView setAnimationDidStopSelector:@selector(didStop:finished:context:)];
  [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
  [UIView setAnimationDuration:1.0f];
  [UIView setAnimationRepeatCount:3];
  [UIView setAnimationRepeatAutoreverses:YES];
  CGPoint center = basketBall.center;
  if(center.y > 85.0f) {
    center.y -= 295.0f;
    basketBall.center = center;
  } else {
    center.y += 295.0f;
    basketBall.center = center;
  }
  [UIView commitAnimations];
}
//END:code.delegation.touchesEnded

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
	// Return YES for supported orientations
	return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


- (void)didReceiveMemoryWarning {
	[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
	// Release anything that's not essential, such as cached data
}


- (void)dealloc {
	[super dealloc];
}

@end
