无法在启用分页的 UIScrollView 中制作一行可点击按钮

发布于 2024-10-04 05:13:38 字数 690 浏览 0 评论 0原文

我正在尝试制作一排可以水平滚动的按钮。就像 Pulse News Reader 应用程序中提要中的新闻条目一样。 我已成功在 UIScrollView 上启用分页,页面大小与按钮的宽度相同。即屏幕上同时出现 3 个按钮, | 1 | 2 | 3 | ,如果我向左滑动,它会变成 | 2 | 3 | 4 |. 我通过使用我在 stackoverflow 中找到的方法实现了这一点:

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { 
    if ([self pointInside:point withEvent:event]) { 
        return scrollView;
    }
   return nil;}

通过在包含按钮行的 UIScrollView 中将 ClipsToBounds 设置为 NO,然后在其顶部覆盖另一个视图以获取滑动手势。 它会移动并完美地卡入位置!

但现在最大的问题是,除了边界内的按钮外,我无法单击按钮!我应该怎么做才能使这些按钮可点击? 我以为我可以获取触摸事件并将其传递给包含这些按钮的 UIScrollView,但我发现一旦使用上述方法,我就无法获得任何 TouchesBegan、touchesEnd、touchesMoved 和 TouchesCancelled 响应。我一直在痛苦地寻找了几天的出路,请为我指明正确的方向。感谢您的关注!

I am trying to make a row of buttons which can be scrolled horizontally. Like the news items in a feed in the Pulse News Reader app.
I've successful made enabled paging on UIScrollView with the page size same as the width of a button. i.e. 3 buttons on the screen at once, | 1 | 2 | 3 | , if I swipe left, it becomes | 2 | 3 | 4 |.
I made this possible by using a method I founded here in stackoverflow:

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { 
    if ([self pointInside:point withEvent:event]) { 
        return scrollView;
    }
   return nil;}

by turning the clipsToBounds to NO in the UIScrollView containing the row of buttons and then overlaying another view on top of it for getting the swipe gestures.
It moves and snap to position perfectly!

But now the biggest problem is that I can't click the buttons except the one inside the bound! What should I do to make those button clickable?
I thought I can get the touch events and pass it to the UIScrollView containing those buttons, but I found that once the above method is used, I can't get any touchesBegan, touchesEnd, touchesMoved and touchesCancelled response to me.I've been finding way out for days painfully, please point me into a correct direction. Thanks for your attention!

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文