Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

With nested UIScrollViews, how do I disable the parent UIScrollView when inner view is being scrolled?

With nested UIScrollViews, how do I disable the parent UIScrollView when inner view is being scrolled?

I have a parent view that is a UIScrollView and one of it's child views in a UITableView (which inherits UIScrollView). When scrolling the inner UITableView, I don't want the other view to scroll.

The behaviour I'm seeing is when scrolling the inner view, it behaves as I want it, until it reaches the end. Once the UITableView has reached the end, the parent UIScrollView starts scrolling. How can I disable this?

If the touch is on the UITableView, the UIScrollView should never scroll.

I tried making a UIView a parent of the UITableView. I gave that view some gesture recognizers, which blocked the gestures from going up to the parent UIScrollView. Almost what I wanted, except my UITableView no longer bounces when trying to scroll past the end.

Anybody know the correct way to get the behaviour I want?

like image 512
Roland Rabien Avatar asked Nov 08 '22 01:11

Roland Rabien


1 Answers

There are several properties, which disable user interaction or scrolling:

collectionView.isScrollEnabled or collectionView.isUserInteractionEnabled

There are also delegate method on scroll view that are being called once scrolling has been finished:

func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) { }

You may just set properties according to your needs, so that scroll view won't scroll at the time table view is scrolling.

Thanks.

like image 149
user3466447 Avatar answered Nov 14 '22 23:11

user3466447