Guest User

Untitled

a guest
Jul 17th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. import UIKit
  2.  
  3. open class AGTapGestureClosure: UITapGestureRecognizer {
  4. private var tapAction: ((UITapGestureRecognizer) -> Void)?
  5.  
  6. public override init(target: Any?, action: Selector?) {
  7. super.init(target: target, action: action)
  8. }
  9.  
  10. public convenience init (
  11. tapCount: Int = 1,
  12. fingerCount: Int = 1,
  13. action: ((UITapGestureRecognizer) -> Void)?) {
  14. self.init()
  15. self.numberOfTapsRequired = tapCount
  16. self.numberOfTouchesRequired = fingerCount
  17. self.tapAction = action
  18. self.addTarget(self, action: #selector(didTap(_:)))
  19. }
  20.  
  21. @objc open func didTap (_ tap: UITapGestureRecognizer) {
  22. tapAction? (tap)
  23. }
  24. }
  25.  
  26. extension UIView {
  27.  
  28. @discardableResult
  29. func tapped(callback: @escaping ((UITapGestureRecognizer) -> Void)) -> AGTapGestureClosure {
  30. self.isUserInteractionEnabled = true
  31. let tapped = AGTapGestureClosure(action: callback)
  32. self.addGestureRecognizer(tapped)
  33. return tapped
  34. }
  35. }
Add Comment
Please, Sign In to add comment