UICollectionView:将Tap Gesture Recognizer添加到collectionView超级视图

时间:2016-06-24 08:53:35

标签: ios uicollectionview

集合视图不称为didSelectItemAtIndexPath。当我将Tap Gesture Recognizer添加到collectionView超级视图时,它总是响应轻击手势方法。

请帮助我,提前致谢!

1 个答案:

答案 0 :(得分:1)

试试这个

func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {
    let touchPoint = touch.locationInView(superView)
    return !CGRectContainsPoint(collectionView.frame, touchPoint)
}

并确保委托已连接:

tapGestureRecognizer.delegate = self