Handling touches for nested UIScrollViews scrolling in the same direction(处理嵌套 UIScrollViews 在同一方向滚动的触摸)
问题描述
我有两个嵌套的 UIScrollView,都在垂直方向滚动.在允许内部滚动视图滚动之前,我需要先将外部滚动视图滚动到它的最大范围.在外部滚动视图达到其最大范围之前,内部滚动视图不应滚动.这是一个插图:
I have two nested UIScrollViews, both scrolling in the vertical direction. I need the outer scrollview to scroll to it's max range first before allowing the inner scrollview to scroll. The inner scrollview should not be scrollable until the outer scrollview has reached it's max range. Here's an illustration:
在左图中,Scrollview B
内的垂直拖动应移动 Scrollview A
并且 Scrollview B
不应滚动(但它仍然需要能够接收触摸/点击).一旦 Scrollview A
达到它的最大范围(当 Scrollview B
到达屏幕顶部时),则 Scrollview B
应该滚动.这需要以一个连续的动作进行.
In the left diagram, a vertical drag inside of Scrollview B
should move Scrollview A
and Scrollview B
should not be scrollable (but it still needs to be able to receive touches/taps). Once Scrollview A
reaches it's max range (when Scrollview B
gets to the top of the screen), then Scrollview B
should scroll. This needs to work in one continuous motion.
我试图从 ScrollView A
的 scrollViewDidScroll:
委托切换 ScrollView B
的 scrollEnabled
方法,但这似乎不是一个可行的解决方案,因为它不能在一个连续运动中工作(例如:用户需要在 Scrollview B
到达屏幕顶部后再次释放并触摸).
I've attempted to toggle ScrollView B
's scrollEnabled
from ScrollView A
's scrollViewDidScroll:
delegate method, but this doesn't appear to be a viable solution because it doesn't work in one continuous motion (eg: The user needs to release and touch again after Scrollview B
reaches the top of the screen).
在一个连续的动作中实现这一点的最佳方法是什么?
What's the best way to implement this such that is works in one continuous motion?
推荐答案
在我的例子中,我解决了为外部 ScrollView 子类化 UIScrollView.
In my case I solved subclassing UIScrollView for the outer ScrollView.
class MYOuterScrollView: UIScrollView, UIGestureRecognizerDelegate
{
override func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool
{
return true
}
func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool
{
return true
}
}
这篇关于处理嵌套 UIScrollViews 在同一方向滚动的触摸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:处理嵌套 UIScrollViews 在同一方向滚动的触摸
基础教程推荐
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01