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

#import "SimpleMovementViewController.h"

@implementation SimpleMovementViewController

- (void)viewWillAppear:(BOOL)animated {
  movingBall = basketBall;
}

//START:code.SimpleMovement.touchesBegan
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
  if(event.allTouches.count > 1) {
    [UIView beginAnimations:@"switch" context:nil];
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp
                           forView:self.view cache:YES]; //<label id="code.simplemovement.transition"/>
    if(nil == basketBall.superview) {
      basketBall.center = tennisBall.center;
      [tennisBall removeFromSuperview];
      [self.view addSubview:basketBall];
      movingBall = basketBall;
    } else {
      tennisBall.center = basketBall.center;
      [basketBall removeFromSuperview];
      [self.view addSubview:tennisBall ];
      movingBall = tennisBall;
    }

    [UIView commitAnimations];
  }
}
//END:code.SimpleMovement.touchesBegan

//START:code.SimpleMovement.touchesEnded
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
  [UIView beginAnimations:@"movement" context:nil]; //<label id="code.coreanimation.simple.touchesEnded"/>
  CGPoint center = movingBall.center;
  if(center.y > 85.0f) {
    center.y -= 295.0f;
    movingBall.center = center;
  } else {
    center.y += 295.0f;
    movingBall.center = center;
  }
  [UIView commitAnimations];
}
//END:code.SimpleMovement.touchesEnded

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

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

@end
