区分webView中js点击事件和tapGesture

在webview中添加手势,必须实现以下代理才有效;

func gestureRecognizer(gestureRecognizer:UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer:UIGestureRecognizer) ->Bool{return true}

若webview中有js的点击事件,如何区分?

经debug发现,js点击事件的gesture属于WKSyntheticClickTapGestureRecognizer,这是个运行时的属性,直接取是取不到的。但是我们可以用description属性,即otherGestureRecognizer.description,返回的是一个描述字符串,实现如下:

func gestureRecognizer(gestureRecognizer:UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer:UIGestureRecognizer) ->Bool{

if otherGestureRecognizer.description.containsString("WKSyntheticClickTapGestureRecognizer") {

return false

} return true }

你可能感兴趣的:(区分webView中js点击事件和tapGesture)