简体   繁体   中英

UIScrollView inside UIScrollView – ignore scroll view touches when in bounds of text view?

I have one UIScrollView inside another UIScrollView , both scrolling vertically. I'm having an issue where when I try to scroll the inner scroll view, the touches are also picked up just afterwards by the outer scroll view. I need touches in the inner scroll view to be exclusively handled by it, and for scrollViewDidScroll to NOT be called on the parent scroll view.

I've tried all manner of things, subclassing the scroll view and overriding hitTest:withEvent , setting canCancelContentTouches , setting exclusiveTouch , nothing work at all. The scrollViewDidScroll methods are fired first on the inner one, then on the outer one.

How can I effectively kill the touch after the first scroll view, and not pass it up the responder chain to the outer scroll view?

(FYI: The hierarchy is that there's a child view controller inbetween, so the outer scroll view contains a child view controller, which in turn contains the inner scroll view).

Apple definitely DOES NOT discourage UIScrollView inside UIScrollView. It's actually in the doc:

your application does not need to do anything to support nesting scrolling. It is supported and provided by default.

https://developer.apple.com/library/content/documentation/WindowsViews/Conceptual/UIScrollView_pg/NestedScrollViews/NestedScrollViews.html

If you want to disable the parent scroll view from scrolling, you can probably send a notification from the child, and set isScrollEnabled in parent.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM