Search code examples
iphoneobjective-ciosipaduiimageview

UITapGestureRecognizer not working in UIImageView


I had the following code:

UITapGestureRecognizer *showStoryTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showNewsStory:)];
[showStoryTapRecognizer setDelegate:self];
[self.storyImageView_ addGestureRecognizer:showStoryTapRecognizer];
[showStoryTapRecognizer release];

This however doesn't trigger the showNewsStory, why is this? I have enabled userInteraction in the image view.


Solution

  • UITapGestureRecognizer *oneTouch=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(OneTouchHandeler)];
    
    [oneTouch setNumberOfTouchesRequired:1];
    
    [imageView addGestureRecognizer:oneTouch];
    
    imageView.userInteractionEnabled = YES;