IDMTapDetectingImageView.m 1.7 KB

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