TouchImageView.m 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //
  2. // TouchImageView.m
  3. // iSales-NPD
  4. //
  5. // Created by Ray on 2/18/16.
  6. // Copyright © 2016 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "TouchImageView.h"
  9. @implementation TouchImageView
  10. @synthesize delegate;
  11. - (instancetype)initWithFrame:(CGRect)frame
  12. {
  13. self = [super initWithFrame:frame];
  14. if (self) {
  15. [self becomeFirstResponder];
  16. self.userInteractionEnabled=true;
  17. UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
  18. longPress.minimumPressDuration = 0.8; //定义按的时间
  19. [self addGestureRecognizer:longPress];
  20. // self.layer.borderColor = [UIColor darkGrayColor].CGColor;
  21. // self.layer.borderWidth = 1.0;
  22. }
  23. return self;
  24. }
  25. - (void)awakeFromNib {
  26. [super awakeFromNib];
  27. [self becomeFirstResponder];
  28. self.userInteractionEnabled=true;
  29. self.layer.borderColor = [UIColor darkGrayColor].CGColor;
  30. self.layer.borderWidth = 1.0;
  31. UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
  32. longPress.minimumPressDuration = 0.8; //定义按的时间
  33. [self addGestureRecognizer:longPress];
  34. // Initialization code
  35. }
  36. /*
  37. // Only override drawRect: if you perform custom drawing.
  38. // An empty implementation adversely affects performance during animation.
  39. - (void)drawRect:(CGRect)rect {
  40. // Drawing code
  41. }
  42. */
  43. - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
  44. if(delegate && [delegate respondsToSelector:@selector(TouchImageViewOnTouche:)])
  45. [delegate TouchImageViewOnTouche:self];
  46. }
  47. -(void)longPress:(UILongPressGestureRecognizer*)gestureRecognizer{
  48. if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
  49. if(delegate && [delegate respondsToSelector:@selector(TouchImageViewOnLongPress:)])
  50. [delegate TouchImageViewOnLongPress:self];
  51. }
  52. }
  53. //- (void)pressesEnded:(NSSet<UIPress *> *)presses withEvent:(nullable UIPressesEvent *)event
  54. //{
  55. // // event
  56. //}
  57. @end