在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?}