UITapGestureRecognizer tap on self.view but ignore subviews

后端 未结 12 806
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-30 21:49

I need to implement a feature that will invoke some code when I double tap on the self.view (view of UIViewCotroller). But the problem that I have other UI obje

12条回答
  •  一个人的身影
    2020-11-30 22:23

    Swift 4:

    touch.view is now an optional, so based on @Antoine's answer:

    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
        if let touchedView = touch.view, touchedView.isDescendant(of: deductibleBackgroundView) {
            return false
        }
        return true
    }
    

提交回复
热议问题