Swift UITAP识别器从UITableView窃取水龙头
如果我使用UITableView识别器,我的UITableView对象不会被点击,但识别器工作良好 点击识别器初始化:Swift UITAP识别器从UITableView窃取水龙头,swift,uitableview,uitapgesturerecognizer,Swift,Uitableview,Uitapgesturerecognizer,如果我使用UITableView识别器,我的UITableView对象不会被点击,但识别器工作良好 点击识别器初始化: let tap = UITapGestureRecognizer(target: self, action: #selector(tapBackground)) menuBackground?.addGestureRecognizer(tap) Windows层次结构: menuBackground?.addSubview(menuWindow!) menuWindow?.
let tap = UITapGestureRecognizer(target: self, action: #selector(tapBackground))
menuBackground?.addGestureRecognizer(tap)
Windows层次结构:
menuBackground?.addSubview(menuWindow!)
menuWindow?.addSubview(menuList!)
它运行良好:
@objc func tapBackground(sender: UITapGestureRecognizer) {
let tapLocation = sender.location(in: menuBackground)
if !menuWindow!.frame.contains(tapLocation) {
closeMenu()
}
}
如果我不使用轻触识别器,它工作得很好,但是如果我使用了轻触识别器,该功能将不起任何作用。为什么?
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print( indexPath.row )
}
添加手势识别器代理,您还应在cellForRowAt中添加UITapGestureRecognitor
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
return true
}
最后我找到了解决办法。tap.cancelsTouchesInView=false