CheckPleaseViewController.m
上传用户:jjjjag8
上传日期:2017-04-17
资源大小:1443k
文件大小:2k
源码类别:

iPhone

开发平台:

MultiPlatform

  1. //
  2. //  CheckPleaseAppDelegate.m
  3. //  CheckPlease
  4. //
  5. //  Created by Jeff LaMarche on 8/3/08.
  6. //  Copyright __MyCompanyName__ 2008. All rights reserved.
  7. //
  8. #import "CheckPleaseViewController.h"
  9. #import "CGPointUtils.h"
  10. @implementation CheckPleaseViewController
  11. @synthesize label;
  12. - (void)eraseLabel {
  13. label.text = @"";
  14. }
  15. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  16. // Return YES for supported orientations
  17. return (interfaceOrientation == UIInterfaceOrientationPortrait);
  18. }
  19. - (void)didReceiveMemoryWarning {
  20. [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
  21. // Release anything that's not essential, such as cached data
  22. }
  23. - (void)dealloc {
  24. [label release];
  25. [super dealloc];
  26. }
  27. #pragma mark -
  28. - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
  29. UITouch *touch = [touches anyObject];
  30. CGPoint point = [touch locationInView:self.view];
  31. lastPreviousPoint = point;
  32. lastCurrentPoint = point;
  33. lineLengthSoFar = 0.0f;
  34. }
  35. - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
  36. UITouch *touch = [touches anyObject];
  37. CGPoint previousPoint = [touch previousLocationInView:self.view];
  38. CGPoint currentPoint = [touch locationInView:self.view];
  39. CGFloat angle = angleBetweenLines(lastPreviousPoint, lastCurrentPoint, previousPoint, currentPoint);
  40. if (angle >= kMinimumCheckMarkAngle&& angle <= kMaximumCheckMarkAngle && lineLengthSoFar > kMinimumCheckMarkLength){
  41. label.text = @"Checkmark";
  42. [self performSelector:@selector(eraseLabel) withObject:nil afterDelay:1.6];
  43. }
  44. lineLengthSoFar += distanceBetweenPoints(previousPoint, currentPoint);
  45. lastPreviousPoint = previousPoint;
  46. lastCurrentPoint = currentPoint;
  47. }
  48. @end