-2

If I use UITapGestureRecognizer, my UITableView objets does not get taps, but the recognizer works well.

Tap recognizer init:

let tap = UITapGestureRecognizer(target: self, action: #selector(tapBackground)) 
menuBackground?.addGestureRecognizer(tap)

Windows hierarchy:

menuBackground?.addSubview(menuWindow!)
menuWindow?.addSubview(menuList!)

It works well:

@objc func tapBackground(sender: UITapGestureRecognizer) {

  let tapLocation = sender.location(in: menuBackground)
  if !menuWindow!.frame.contains(tapLocation) {
      closeMenu()
  }
}

It works well if i do not use the tap recognizer, but if i use that, this function does nothing. Why?

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    print( indexPath.row )
 }
HaZe
  • 53
  • 2
  • 4

1 Answers1

1

Add gesture recognizer delegate and also, your should add your UItapGestureRecognizer in the cellForRowAt.

 func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
    return true
}
Celeste
  • 1,519
  • 6
  • 19