处理嵌套 UIScrollViews 在同一方向滚动的触摸

时间:2022-12-30
本文介绍了处理嵌套 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 AscrollViewDidScroll: 委托切换 ScrollView BscrollEnabled方法,但这似乎不是一个可行的解决方案,因为它不能在一个连续运动中工作(例如:用户需要在 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 在同一方向滚动的触摸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

上一篇:UIStackView - 从中​​心均匀分布视图 下一篇:iOS:在用户向下拖动时拉伸/调整 UITableView 标题的

相关文章

最新文章