在UIScrollView中滚动UITableView [英] Scrolling a UITableView inside a UIScrollView

查看:139
本文介绍了在UIScrollView中滚动UITableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UITableView 这是一个 UIView 的子视图,然后 UIView UIScrollView 的子视图。如何检测应该滚动 UITableView

I have a UITableView which is a subview of a UIView, then that UIView is a subview of a UIScrollView. How do I detect the touches that should scroll the UITableView?

code>可以获得项目选择事件(表中的单元格被选择/点击)很好,除了你必须按住单元格之前,它被触发。但我不能让 UITableView 滚动,它总是对平移手势作出反应的 UIScrollView

The UITableView can get item selection events (a cell in the table is selected/tapped) just fine, except that you have to hold down on the cell before it fires. But I can't get the UITableView to scroll, its always the UIScrollView that reacts to the pan gesture.

任何帮助都非常感谢。提前感谢!

Any help is greatly appreciated. Thanks in advance!

编辑:
解决,尽管我提出了错误的问题。它默认工作,罗马K指出。我认为问题是与 UIScrollView (<$ c>)的边界之外的 UITableView $ c> UITableView 超过了 UIScrollView 的底部边界。将其设置为正确适合 UIScrollView 内。

Solved, though I asked the wrong question. It does work by default as Roman K pointed out. I think the problem was related to having a part of the UITableView outside the bounds of the UIScrollView (the UITableView went over the bottom bounds of the UIScrollView). Setting it to correctly fit inside the UIScrollView fixed it.

推荐答案

,请确保 UIScrollView的属性 delaysContentTouches canCancelContentTouches 适当地。它们控制UIScrollView实例如何将触摸信息传递到其子视图。默认情况下, delaysContentTouches 设置为YES。此外,如果您在子视图中扩展 UIScrollView touchesShouldBegin:withEvent:inContentView:

Please, make sure that UIScrollView's properties delaysContentTouches and canCancelContentTouches are set appropriately. They control how UIScrollView instance passes touch information to its subviews. By default delaysContentTouches is set to YES. Also, make sure that, if you extended UIScrollView, touchesShouldBegin:withEvent:inContentView: allow touches in the subview.

否则,在您的场景中,默认情况下, UITableView 滚动应该起作用。如果你创建一个只有视图层次结构的测试项目,你会看到的情况。所以,比较两者,看看什么差异影响滚动。

Otherwise, UITableView scrolling should work by default in your scenario. If you create a test project with just the view hierarchy as described you will see that it is the case. So, compare the two and see what difference affects the scrolling.

这篇关于在UIScrollView中滚动UITableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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