How can I nest a UIScrollView inside a UIScrollVie

2019-02-13 01:09发布

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?

4条回答
疯言疯语
2楼-- · 2019-02-13 01:39

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.

查看更多
再贱就再见
3楼-- · 2019-02-13 01:41

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.

查看更多
SAY GOODBYE
4楼-- · 2019-02-13 01:45

I did this and it does cause the parent scrollView NOT to scroll anymore which is fine but my child scrollView which was pushed via presentModalViewController still does not respond to scroll events (e.g. scrolling up or down). I'm obviously missing something...

EDIT: Got it to work finally by using 'scrollEnabled' on the parent view. Thanks.

查看更多
爱情/是我丢掉的垃圾
5楼-- · 2019-02-13 01:57

I had this same problem till I set dynamically enough height to the contentSize of the inner ScrollView, using:

[scrollView setContentSize:CGSizeMake(scrollView.frame.size.width,600)];

Obviously this is just a hardcoded example, you should set the height needed to display the whole content of the view, and maybe no scroll is needed in the end.

It seems that setting the height of the scrollView using the IBuilder is not enough, so no scroll was needed and that's why I was thinking that the sweep event wasn't reaching the inner scroll.

Hope this helps!

查看更多
登录 后发表回答