Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func addTapGesture(action: @escaping () -> Void) {
- let tapGesture = UITapGestureRecognizer { (gr) in
- print("UITapGestureRecognizer fire")
- switch gr.state {
- case .ended:
- self.backgroundColor = UIColor.clear
- action()
- default:
- return
- }
- }
- let longPressGesture = UILongPressGestureRecognizer { (gr) in
- print("UILongPressGestureRecognizer fire")
- switch gr.state {
- case .began:
- self.backgroundColor = UIColor.lightGray
- case .ended:
- self.backgroundColor = UIColor.clear
- action()
- default:
- return
- }
- }
- longPressGesture.minimumPressDuration = 0.05
- longPressGesture.cancelsTouchesInView = false
- self.addGestureRecognizer(tapGesture)
- self.addGestureRecognizer(longPressGesture)
- }
Add Comment
Please, Sign In to add comment