MWTapDetectingImageView.m 1.6 KB

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