0
votes

I've searched through other questions similar to this on SO already, and came up empty with a solution to my problem. For some reason, my UIImageView (which I've added to a UIView in storyboard) just won't recognize a tap gesture I've created. User Interaction is enabled, as is multiple touch. My selector method just never gets called.

self.image is my imageView property that I've added onto a UIView.

- (void)viewDidLoad {
    [super viewDidLoad];
    self.image.image = [UIImage imageNamed:@"mountainWallpaper.png"];
    [self gesture];
}

-(void)gesture {

    UITapGestureRecognizer *imageTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(imageTapped:)];
    //imageTap.numberOfTapsRequired = 1;
    //imageTap.numberOfTouchesRequired = 1;
    imageTap.delegate = self;

    [self.image addGestureRecognizer:imageTap];

}

-(IBAction3)imageTapped:(UIGestureRecognizer *)tap {
    NSLog(@"test");
}

Any suggestions? I've looked through most other questions I found and tried out various solutions with no such luck. Many answers said to verify that user interaction is enabled, to make sure the delegate is set...I've tried much of what has been suggested already.

I've also experimented with first adding the UIView as the tap gesture target, adding the imageView itself as the target, adding the gesture to both the UIView and the imageView...nothing.

In storyboard, I have my UIImageView connected to my viewController as both the view and the image. I generally do things programmatically so I have to get used to connecting objects in IB, I'm pretty bad at it.

2
Check if the self.image.userInteractionEnabled = YES;. also where is your UIImageView place? Because something my be blocking the interaction,rob180
@rob180 as mentioned in the question, userInteraction is already enabled through storyboard. This overrides the default value being set to "NO". What do you mean by where is it placed? In storyboard, I have a UIImageView atttached to a UIView attached to a ViewController.karan satia
make sure nothing in over the UIImageViewrob180
@rob180 there is nothing above it except the view controller.karan satia
is this IBAction3 a mistake here or you have it on the code?rob180

2 Answers

1
votes

Check for following points may be it will helpful for you :

  • Make sure your UIImageView User interaction is enable .
  • Image View priority should be on top over super view .
  • make sure super view of Image view userIntration is also enable .
  • have you added UI gesture Delegate ?
1
votes

It looks like you have a spelling mistake. Try changing IBAction3 to IBAction or void:

-(void)imageTapped:(UIGestureRecognizer *)tap {
    NSLog(@"test");
}