shouldReceiveTouch on UITableViewCellContentView

后端 未结 5 517
清歌不尽
清歌不尽 2020-12-31 07:27

I\'m trying to ignore UITapGestureRecognizer taps on a UITableView with the following:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer sho         


        
5条回答
  •  情歌与酒
    2020-12-31 07:48

    Here's the swift solution for the selected answer.

    I couldn't use the "MyTableView" named dependency check because I had a custom BaseViewController that many view controllers derive from. Some view controllers have a tableview, some have a collection view or both but in all cases the gesture recognizer steals their touches.

    I didn't want to put this gesture handling code in every subclass, so the only way I got it working in the base class is this:

    extension BaseViewController: UIGestureRecognizerDelegate {
    
        func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {
            var view = touch.view
            while view != nil {
                if view!.isKindOfClass(UICollectionView) || view!.isKindOfClass(UITableView) {
                    return false
                } else {
                    view = view!.superview
                }
            }
            return true
        }
    
    }
    

提交回复
热议问题