UIScrollView内部的UIScrollView –在文本视图的边界内忽略滚动视图的触摸吗? [英] UIScrollView inside UIScrollView – ignore scroll view touches when in bounds of text view?

查看:53
本文介绍了UIScrollView内部的UIScrollView –在文本视图的边界内忽略滚动视图的触摸吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在另一个 UIScrollView 中有一个 UIScrollView ,两者都垂直滚动.我遇到一个问题,当我尝试滚动内部滚动视图时,紧随其后的还有外部滚动视图的触摸.我需要内部滚动视图中的触摸由它独占处理,并且要在父滚动视图上不调用 scrollViewDidScroll .

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.

我已经尝试了所有方法,将滚动视图子类化,并覆盖了 hitTest:withEvent ,设置了 canCancelContentTouches ,设置了 exclusiveTouch ,什么都没有工作. scrollViewDidScroll 方法首先在内部方法中触发,然后在外部方法中触发.

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绝对不劝阻UIScrollView内部的UIScrollView.它实际上在文档中:

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

如果要禁止父级滚动视图滚动,则可以从子级发送通知,并在父级中设置 isScrollEnabled .

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.

这篇关于UIScrollView内部的UIScrollView –在文本视图的边界内忽略滚动视图的触摸吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆