The issue happens because touchesBegan
is interfering with the scroll gesture on the first touch. Instead of recognizing the scroll, the collection view thinks it's just a touch.
Remove these lines from touchesBegan
and touchesEnded
:
self.next?.touchesBegan(touches, with: event)
self.next?.touchesEnded(touches, with: event)
These lines forward touches manually, which disrupts scrolling.
Override gestureRecognizerShouldBegin
to ensure scrolling works:
override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
return gestureRecognizer is UIPanGestureRecognizer
}
This makes sure scrolling is detected properly.
The collection view will now correctly recognize the first scroll.
touchesBegan
will no longer stop scrolling from working.
After these changes, scrolling will work as expected on the first touch. 🚀