Skip to content

Instantly share code, notes, and snippets.

@ericjames
Last active August 22, 2017 20:12
Show Gist options
  • Save ericjames/34a3e5cd16174d88fe4e2667f4e2a44f to your computer and use it in GitHub Desktop.
Save ericjames/34a3e5cd16174d88fe4e2667f4e2a44f to your computer and use it in GitHub Desktop.
Swift 3 - Listen in on UIGestureRecognizer INSIDE of a UIWebView
class WebViewController: UIViewController, UIGestureRecognizerDelegate {
@IBOutlet weak var webView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
// WebView: Register tap
let panGesture = UITapGestureRecognizer(target: self, action: #selector(doneDragging(_:)))
panGesture.delegate = self
webView.addGestureRecognizer(panGesture)
}
// Function
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
print("Gesture",gestureRecognizer)
if (gestureRecognizer is UITapGestureRecognizer && gestureRecognizer.state == UIGestureRecognizerState.ended) {
return true
} else {
return false
}
}
func doneDragging(_ sender: UITapGestureRecognizer)
{
print("Touches ended")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment