Created
August 9, 2021 16:24
-
-
Save natebirkholz/ce01a5abd07a44f5a694929cdc03c8e8 to your computer and use it in GitHub Desktop.
This file contains 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 ClosureGestureRecognizer<GestureRecognizer: UIGestureRecognizer> { | |
fileprivate var recognizer: GestureRecognizer | |
private var actionHandler: ((GestureRecognizer) -> Void) | |
init(action: @escaping (GestureRecognizer) -> ()) { | |
self.recognizer = GestureRecognizer() | |
self.actionHandler = action | |
self.recognizer.addTarget(self, action: #selector(handleAction)) | |
} | |
@objc private func handleAction() { | |
actionHandler(recognizer) | |
} | |
} | |
extension UIView { | |
func addGestureRecognizer(_ gestureRecognizer: ClosureGestureRecognizer) { | |
self.addGestureRecognizer(gestureRecognizer.recognizer) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment