How to detect of tap gesture is from uiwebview or

2019-09-04 17:27发布

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条回答
趁早两清
2楼-- · 2019-09-04 17:33
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.

查看更多
登录 后发表回答