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

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

问题描述

我有一个 UITableView,它是 UIView 的子视图,然后 UIViewUIScrollView 的子视图代码>.如何检测应该滚动 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?

UITableView 可以获得项目选择事件(表格中的一个单元格被选中/点击)就好了,除了你必须在它触发之前按住单元格.但是我无法让 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!

解决了,虽然我问错了问题.正如 Roman K 指出的那样,它默认工作.我认为这个问题与 UITableView 的一部分超出了 UIScrollView 的边界有关(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's 属性 delaysContentTouchescanCancelContentTouches适当地.它们控制 UIScrollView 实例如何将触摸信息传递给它的子视图.默认情况下,delaysContentTouches 设置为 YES.另外,请确保,如果您扩展了 UIScrollViewtouchesShouldBegin: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天全站免登陆