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

情到浓时终转凉″ 提交于 2019-12-11 02:03:29

问题


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).


回答1:


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.



来源:https://stackoverflow.com/questions/26512338/uiscrollview-inside-uiscrollview-ignore-scroll-view-touches-when-in-bounds-of

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!