Last active
November 5, 2017 23:04
-
-
Save llinardos/5d35495080cbceba062be487d31fd242 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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