判断 UITapGestureRecognizer 是否点击在某个 view 上

Show Code

1
2
3
4
5
6
func viewTapped (_ sender: UITapGestureRecognizer) {
guard let touchedView = sender.view else { return }
let point = sender.location(in: touchedView)
let convertedPoint = targetView.convert(point, from: touchedView)
print(targetView.layer.contains(convertedPoint))
}