karan satia
karan satia

Reputation: 319

UIImageView won't recognize tap gesture

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.

Upvotes: 0

Views: 193

Answers (2)

user3784214
user3784214

Reputation: 105

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

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

Upvotes: 1

Alok
Alok

Reputation: 25938

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 ?

Upvotes: 1

Related Questions