0

I have a View generated like this :

oneView = [[UIView alloc] initWithFrame:CGRectMake(x, y , w, h)];
oneView.tag = i;

UITapGestureRecognizer* recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap2:)];
[recognizer setNumberOfTouchesRequired:1];
[oneView addGestureRecognizer:recognizer];
recognizer.delegate = self;
[recognizer release];

- (void)handleSingleTap2:(UITapGestureRecognizer *)recognizer {
    int viewID = recognizer.view.tag;
    NSLog(@"id : %d", viewID);
}

This works, but if I replace the UIView alloc with a UIWebView or UIImageView alloc, then touch event is not triggerred anymore.

How may I make it work ?

Oliver
  • 23,072
  • 33
  • 138
  • 230

3 Answers3

0

set userInteractionEnabled=YES and if needed multipleTouchEnabled=YES

Tomasz Stanczak
  • 12,796
  • 1
  • 30
  • 32
0

Regarding your question about the UIWebView I suggest you have a look at drawnonward's Answer :

Does UIGestureRecognizer work on a UIWebView?

And for the UIImageView Part see this Tutorial:

UIImageView-with-zooming-tapping

I could not paste the code here but i think this will keep this area cleaner and easier to read.

Community
  • 1
  • 1
Ahmad Kayyali
  • 8,233
  • 13
  • 49
  • 83
0

you must override

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer;

delegate function and return YES;

cekisakurek
  • 2,474
  • 2
  • 17
  • 28