问题
Hello everyone I have a uitapgesture on my view using the following code :
UITapGestureRecognizer *tap= [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(TAPGestureRecognizer)];
tap.numberOfTapsRequired=1;
tap.delegate = self;
[self.view addGestureRecognizer:tap];
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
And I have a uiwebview as a subview in my UIview. The problem is that on the uivewview HTML it had a onclick(); which in turn is calling the tapgesture. Any help?
回答1:
FirstView.image=[UIImage imageNamed:@"shape1.jpg"];
FirstView.tag=1;
FirstView.userInteractionEnabled=YES;
[FirstView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(firstimagetouch:)]];
SecondWebView.tag=2;
SecondWebView.userInteractionEnabled=YES;
[SecondWebView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(firstimagetouch:)]];
-(void)firstimagetouch:(UIGestureRecognizer *)sender
{
UIView * view=sender.view;
NSLog(@"%ld",(long)view.tag);
}
try like this first add gesture recognizer to view and then your webview according to give him tag value and get tag value. and do what you want.
来源:https://stackoverflow.com/questions/18887757/how-to-detect-of-tap-gesture-is-from-uiwebview-or-self-view