How to detect of tap gesture is from uiwebview or self.view?

折月煮酒 提交于 2019-12-11 19:44:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!