Skip to content

Instantly share code, notes, and snippets.

@llinardos
Last active November 5, 2017 23:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save llinardos/5d35495080cbceba062be487d31fd242 to your computer and use it in GitHub Desktop.
Save llinardos/5d35495080cbceba062be487d31fd242 to your computer and use it in GitHub Desktop.
class Tap {
private var view: UIView
private var action: () -> Void
init(view: UIView, action: @escaping () -> Void) {
self.view = view
self.action = action
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(onTap(_:)))
view.addGestureRecognizer(tapGesture)
}
@objc private func onTap(_ gesture: UIGestureRecognizer) {
if (gesture.state == .ended) {
fireAction()
}
}
fileprivate func fireAction() {
action()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment