IDMTapDetectingView.m 1.4 KB

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