Search code examples
iosswiftuiscrollviewtouchstackview

How to make ScrollView consume touch event even when it's scrolled to the end?


I have an FSPagerView, which has an item that contains scrollable barchart (scrollview having multiple stackviews). When I scroll barchart, if there is a scrollable space, then touch event is consumed by the barchart and it scrolls. If there is no scrollable space on a side and I keep scrolling to that side touching barchart, it does not consume touch event anymore and instead the whole FSPagerView scrolls. How can I make scrollview consume touch event even in such case? In short, I don't want to scroll FSPagerView when touching barchart.

Here is a video: https://streamable.com/kuxta


Solution

  • You can prioritize the UIGestureRecognizer of the two scroll views using the require(toFail:) method.

    Here is the code I tried:

    scrollView.panGestureRecognizer.require(toFail: collectionView.panGestureRecognizer)
    

    I don't know if it's exactly what you were looking for. As soon as the collectionView.panGestureRecognizer detects something, the scroll view won't scroll.