Guest User

Untitled

a guest
Oct 17th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. func addTapGesture(action: @escaping () -> Void) {
  2. let tapGesture = UITapGestureRecognizer { (gr) in
  3. print("UITapGestureRecognizer fire")
  4. switch gr.state {
  5. case .ended:
  6. self.backgroundColor = UIColor.clear
  7. action()
  8. default:
  9. return
  10. }
  11. }
  12.  
  13. let longPressGesture = UILongPressGestureRecognizer { (gr) in
  14. print("UILongPressGestureRecognizer fire")
  15. switch gr.state {
  16. case .began:
  17. self.backgroundColor = UIColor.lightGray
  18. case .ended:
  19. self.backgroundColor = UIColor.clear
  20. action()
  21. default:
  22. return
  23. }
  24. }
  25. longPressGesture.minimumPressDuration = 0.05
  26. longPressGesture.cancelsTouchesInView = false
  27.  
  28. self.addGestureRecognizer(tapGesture)
  29. self.addGestureRecognizer(longPressGesture)
  30. }
Add Comment
Please, Sign In to add comment