How to add gesture recognizer in UIImageview?

The project has UIViewmyView and UIImageViewmyImage behind myView, a view hierarchy:

UIWindow
| - Hunting and fishing | - Hunting and fishing

Then added gesture recognizer in myImage in ViewController

UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
        tapGesture.numberOfTapsRequired = 1;
        [myImage addGestureRecognizer:tapGesture];

But the gesture does not affect myImage, myImage has setUserInteractionEnabled:YES. This will only affect when myImage is placed in front of myView, how can I solve this problem?

+5
source share
2 answers

Yours UIViewwill obviously grab the strokes before they can reach UIImageView.

UIImageView UIView UIView, .

, , :

  • UIView UIImageView, ( , , UIImageView ), (userInteractionEnabled = NO) UIView UIImageView, UIImageView
  • UIView UIImageView (userInteractionEnabled = YES), , , UIView pointInside:withEvent:, hitTest:withEvent:.

Apple, .

+11

:

UILongPressGestureRecognizer *press = [[UILongPressGestureRecognizer alloc] 
initWithTarget:self action:@selector(hasLongPressed)];
[press setMinimumPressDuration:0.1f]; //1ms
press.delegate = (id)self;
[self.DGEMLogo addGestureRecognizer:press];

1). GestureRecognizer UIImageView (self.DGEMLogo) [self.DGEMLogo addGestureRecognizer: ];

2). UIImage Interaction TRUE

.

+1

All Articles