0

I have a view that's a collection view subview. And If I pan on that view I would like to move that view. But what happens is that collection view scrolls a bit until I turn scrolling off in gesture begin event. So I've tried no just skip the touch event for collection view pan like that:

func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
    if gestureRecognizer == collectionView!.panGestureRecognizer && item.frame.contains(touch.location(in: self.collectionView!)) == true {
        return false
    }
    return true
}

But the problem still persists, collection view still scrolls..

HelloimDarius
  • 695
  • 5
  • 23

2 Answers2

1

UICollectoinView is a subclass of UIScrollView, try exploring posts that address multi gestures on a UIScrollView, you can start here:

ScrollView gesture recognizer eating all touch events

Aaron Halvorsen
  • 2,610
  • 1
  • 23
  • 31
0

Okay, so ended up doing like so (not sure if it's the best answer, but at least it works) :

func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {

        if let panGesture = gestureRecognizer as? UIPanGestureRecognizer, let otherPanGesture = otherGestureRecognizer as? UIPanGestureRecognizer {
            if panGesture == self.collectionView?.panGestureRecognizer && item.frame.contains(otherPanGesture.location(in: self.collectionView!)) == true ||
                otherPanGesture == self.collectionView?.panGestureRecognizer && item.frame.contains(panGesture.location(in: self.collectionView!)) == true {
                return false
            }
            return true
        }
}
HelloimDarius
  • 695
  • 5
  • 23