well before i ask this i try the other solutions and it didn't work
this is my code
override func viewDidLoad() {
super.viewDidLoad()
let tapGesture = UITapGestureRecognizer(target: self, action: "didTouchBoard:")
view.addGestureRecognizer(tapGesture)
tapGesture.cancelsTouchesInView = true
}
when i click anywhere it will hide the keyboard if exist , but if i click on tableviewcell or collectionviewcell , it won't click
i try this tapGesture.cancelsTouchesInView , but not work
If you want table view to receive touch, then change tapGesture.cancelsTouchesInView
tapGesture.cancelsTouchesInView = false
You have to add the UITextFeildDelegate methods to enable and disable tap gesture in the view
let tapGesture = UITapGestureRecognizer(target: self, action: "didTouchBoard:")
implement the following methods
func textFieldDidBeginEditing(textField: UITextField) {
self.view.addGestureRecognizer(self.tapGesture) }
func textFieldDidEndEditing(textField: UITextField) { self.view.removeGestureRecognizer(self.tapGesture) }
i think that might work for you
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With