MWTapDetectingView.m 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. //
  2. // UIViewTap.m
  3. // Momento
  4. //
  5. // Created by Michael Waterfall on 04/11/2009.
  6. // Copyright 2009 d3i. All rights reserved.
  7. //
  8. #import "MWTapDetectingView.h"
  9. @implementation MWTapDetectingView
  10. - (id)init {
  11. if ((self = [super init])) {
  12. self.userInteractionEnabled = YES;
  13. }
  14. return self;
  15. }
  16. - (id)initWithFrame:(CGRect)frame {
  17. if ((self = [super initWithFrame:frame])) {
  18. self.userInteractionEnabled = YES;
  19. }
  20. return self;
  21. }
  22. - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
  23. UITouch *touch = [touches anyObject];
  24. NSUInteger tapCount = touch.tapCount;
  25. switch (tapCount) {
  26. case 1:
  27. [self handleSingleTap:touch];
  28. break;
  29. case 2:
  30. [self handleDoubleTap:touch];
  31. break;
  32. case 3:
  33. [self handleTripleTap:touch];
  34. break;
  35. default:
  36. break;
  37. }
  38. [[self nextResponder] touchesEnded:touches withEvent:event];
  39. }
  40. - (void)handleSingleTap:(UITouch *)touch {
  41. if ([_tapDelegate respondsToSelector:@selector(view:singleTapDetected:)])
  42. [_tapDelegate view:self singleTapDetected:touch];
  43. }
  44. - (void)handleDoubleTap:(UITouch *)touch {
  45. if ([_tapDelegate respondsToSelector:@selector(view:doubleTapDetected:)])
  46. [_tapDelegate view:self doubleTapDetected:touch];
  47. }
  48. - (void)handleTripleTap:(UITouch *)touch {
  49. if ([_tapDelegate respondsToSelector:@selector(view:tripleTapDetected:)])
  50. [_tapDelegate view:self tripleTapDetected:touch];
  51. }
  52. @end