Add a UITapGestureRecognizer to a UIWebView

时光怂恿深爱的人放手 提交于 2019-11-29 02:59:10

I found that I had to implement this method to get it to work:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return YES;
}

Your UIViewController subclass should implement UIGestureRecognizerDelegate and return YES from gestureRecognizer: shouldReceiveTouch: when appropriate.

Then you can assign it to the delegate property of your UIGestureRecognizer.

tap.delegate = self;
  1. Add UIGestureRecognizerDelegate to view controller

    <UIGestureRecognizerDelegate>
    
  2. Add Tap Gesture to Webview.

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(flip)];
    tap.numberOfTapsRequired = 1;
    tap.delegate = self;
    [_webview addGestureRecognizer:tap];
    
  3. - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer    shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
        return YES;
    }
    
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!