双水平滚动视图触摸的问题

发布于 2024-10-14 07:51:16 字数 477 浏览 4 评论 0原文

我已经处理这个问题好几个星期了,但仍然没有解决方案。请帮忙。

我有一个带有图像的大滚动视图。每个图像都是屏幕宽的,并且启用了分页。

在这个滚动视图的底部,我有另一个带有按钮的滚动视图。每个图像的每个按钮。当我按下图像按钮时,大滚动视图跳转到图像。

因为我有很多图像,所以我在小滚动视图上有很多按钮。

现在,大滚动条和小滚动条工作正常,按钮也工作正常。

我的问题从小卷轴的远端开始。当我位于小卷轴的末尾(但仍在大卷轴的中间)时,当我将手指移动到死胡同时,我不希望大卷轴移动。你可以说我想将小滚动条与大滚动条分开,但仍然将他保留为子视图(因为我希望它与大滚动条一起移动)。

我尝试过对小滚动条、按钮进行子类化,覆盖 hitTest 和 TouchsBegan/End 但到目前为止什么也没有。

我真的很沮丧,因为我的客户要求这按他的方式工作。

我已经用谷歌搜索了很长时间,但我找不到任何东西!

天哪!

I've been dealing with this problem for weeks, and still no solution. please help.

I have a big scroll view with images. each image is screen wide, and paging enabled.

on this scroll view, in the bottom, i have another scroll view with button. each button for each image. when i push the image button, the big scroll view jump to the image.

since i have a lot of images, i have a lot of buttons on the little scroll view.

right now, the big scroll and small scroll are working ok, and the buttons also.

my problem start at the far ends of the little scroll. when i'm in the end of the little scroll (but still in the middle of the big one) i don't want the big one to move when i move my finger to the dead end. you can say i want to separate the small scroll from the big one, but still leave him as a subview (because i want it to move with the big one).

i've tried subclassing the little scroll, the buttons, override hitTest and touchesBegan/End but nothing so far.

i'm realy realy frustrated because my costumer demands this to work his way.

i've been googled for so long and i can't find anything!

HELLLPPPPP!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

埖埖迣鎅 2024-10-21 07:51:16

这是我发现在我的一个项目中非常宝贵的一段代码:

- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    UIView* result = [super hitTest:point withEvent:event];

    if (/* result or any of its superviews are equal to your little scroll view */) {
        [self setContentOffset:CGPointZero animated:YES];
        self.scrollEnabled = NO;
    } else {
        self.scrollEnabled = YES;    
    }
    return result;
}

如果我正确理解你的问题,我认为这会给你带来所需的行为。我在 if 语句(注释)中有一些伪代码,因为遍历所有超级视图需要循环,这会使代码变得更加复杂,但是如果您熟悉视图层次结构,您通常可以找到更简单的解决方案。

我希望这对您有所帮助,如果您在理解代码时遇到任何困难,我很乐意为您提供解释。

编辑:基本思想是,如果您的手指触摸小滚动视图,则在大滚动视图中关闭滚动,这样大滚动视图就不会滚动。如果您的手指没有触摸小滚动视图,则大滚动视图的滚动将重新打开并且应该表现正常。

Here is a piece of code that I found to be invaluable in one of my projects:

- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    UIView* result = [super hitTest:point withEvent:event];

    if (/* result or any of its superviews are equal to your little scroll view */) {
        [self setContentOffset:CGPointZero animated:YES];
        self.scrollEnabled = NO;
    } else {
        self.scrollEnabled = YES;    
    }
    return result;
}

If I understood your question correctly I think this will give you the desired behavior. I have some pseudo code in the if statement (the comment), since going through all the superviews would require looping, which would make the code much more complicated, but if you're familiar with your view hierarchy you can often find a simpler solution.

I hope this helps and if you're having any trouble understanding the code I'll be happy to give you an explanation.

EDIT: The basic idea is that you turn of scrolling in the big scroll view if your finger is touching the little scroll view, so that the big scroll view won't scroll. If your finger isn't touching the little scroll view, the scrolling of the big scroll view is turned back on and should behave as normal.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文