iphone – 嵌套的UITableViews:同时滚动外部垂直UITableView和子水平UITableView的方法?

当您使用非典型嵌套UITableViews设置时 – 您有一个外部垂直UITableView,它承载90°旋转的UITableViews(参见:
Looking for a UI library to present Data horizontaly in iOS):

有没有办法让iOS处理同时进行垂直和水平触摸?

我发现iOS在处理触摸时非常聪明:
水平触摸使相关的水平UITableView滚动,而垂直滑动使外部UITableView滚动.完善.

只是,我希望能够对角地移动我的手指并同时看到外部UITableView和内部UITableView滚动.

我尝试了一些方法(使用canCancelContentTouches,delayedContentTouches和touch消息),但我还没有找到一种方法来实现这一点.

编辑:
这是一个显示此行为的XCode4项目:http://marcanton.io/other/stackoverflow/nestedtableviews.zip

编辑:
我将此问题提交给Apple Developer Technical Support,以下是他们的回复:

Thank you for writing to Apple
Worldwide Developer Technical Support.
I am responding to your inquiry
concerning touch events in embedded
UITableViews.

Typically this is an approach that is
not recommended. The issue is that
UITableView inherits from UIScrollView
and as stated in the documentation for
UIScrollView:

“Important: You should not embed
UIWebView or UITableView objects in
UIScrollView objects. If you do so,
unexpected behavior can result because
touch events for the two objects can
be mixed up and wrongly handled.”

07002

So that this time, there is not a
workaround for getting both to scroll
at the same time.

I recommend that you file an
enhancement request at
07003
detailing what you would like to see
us add in a future release.

尽管如此,我认为必须有一种方法来启用此功能,但我知道不建议这样做.事实上,Apple甚至不建议在另一个UITableView中托管UITableViews,但除了上面提到的例外,它的工作非常精彩.
我会用我们的集体调查结果更新这个问题.

编辑:实际上有一种方法,详情请参阅:http://marcanton.io/blog/nested-orthogonal-tableviews/

最佳答案 这必须是截取的触摸事件的自定义镜像.触摸事件遵循
responder chain model,这意味着如果响应者链中的对象(最顶层(最外层)视图)无法处理事件或操作,它会将消息重新发送给下一个响应者(在本例中为链中的后台UITableView) ).这就是为什么你看到水平事件转到水平UITableView和垂直事件转到垂直UITableView.对角线触摸事件具有适用的水平和垂直事件,因此最顶层视图(外部垂直UITableView)可以响应垂直触摸并吞下事件.

如果你考虑一下,所有的垂直触摸都可能会有一些水平事件(考虑一下你的手指轻弹),所以在后台可能会做一些工作来确定如何解释触摸事件(或者作为一个垂直事件)或水平).

我发现这个tread将事件传递给响应者链中的下一个对象.您可能想尝试将此作为您拼图的部分解决方案.其余的是弄清楚如何捕获水平触摸事件并将它们传递给下一个响应者.

点赞