Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I nest a UIScrollView inside a UIScrollView, so that the user can scroll the inner UIScrollView?

I haven't tried that yet, but I assume that I would have to disable scrolling of the parent scroll view as soon as I know that the user will want to scroll in the child scroll view, right?

Both scroll views are scrolling horizontal.

How could I disable scrolling detection of the parent temporarily? Or is there some other way?

like image 736
Thanks Avatar asked May 26 '09 12:05

Thanks


2 Answers

UIScrollView has a property called scrollEnabled, which you can set to NO to disable scrolling in your parent scroll view.

I haven't tried it yet, but you may just find that it Does The Right Thing, i.e., the inner scroll view scrolls until it can't scroll any more, at which point the outer scroll view scrolls.

like image 132
hatfinch Avatar answered Nov 01 '22 11:11

hatfinch


It is very possible. The easiest way is to disable the scrollEnabled property, you can also try set the outer UIScrollView's contentSize to its bounds, so that it won't scroll. Depending on what you need, you may set No to bounce as well but that'll basically make your scroll view like a regular UIView.

If you have control over all the child UIScrollView's, you can implement UIScrollViewDelegate protocol, but if you don't, or your child UIScrollView is really a UITableView, or UICollectionView, then you can't really rely the UIScrollViewDelegate protocol, but remember UIScrollView comes with a panGestureRecognizer and you can play with that. A powerful but heavy handed way is to add an observer on the panGestureRecognizer's state property so that you can capture all the events without being the delegate of the UIScrollView in question.

like image 2
BrianDotNet Avatar answered Nov 01 '22 12:11

BrianDotNet