在多个 UIGestureRecognizer 实例之间拆分触摸序列

发布于 2024-09-28 03:10:01 字数 795 浏览 1 评论 0原文

我正在开发一个 iPhone/iPad 应用程序,支持在表视图之间拖动项目。由于所有表格都不适合屏幕,因此我编写了一个自定义 UIScrollView 来水平放置它们,并支持分页。

虽然我已经完成了主要的拖放操作,但仍有一些我无法解决的问题。

  1. 选择要拖动的项目并进行拖动后,无法滚动 UIScrollView 来找到目标 UITableView

  2. 有时,用户可能希望将项目拖动到同一表格视图内。但是一旦开始拖动,表格视图就不再识别滚动手势。

我尝试了各种不同的选项,包括实现 UIGestureRecognizerDelegate 并允许多个手势识别器同时识别手势。

我认为这个问题源于事件处理指南中的描述:“iOS 将触摸屏幕的一个或多个手指识别为多点触控序列的一部分。此序列从第一个手指触摸屏幕时开始,到第一个手指触摸屏幕时结束。最后一根手指从屏幕上移开。”

UIGestureRecognizer 实例始终与整个序列匹配。就我而言,我想将单个序列拆分为离散手势 - 某些触摸识别项目的拖动,而同一序列中的不同触摸应识别为滑动或滚动手势。实际上,我希望我的手势识别器能够同时识别,但只能识别不同的触摸。一旦一个人将触摸识别为手势的一部分,其他人就应该忽略该触摸。

我还没有找到一种方法来使用默认的 UIGestureRecognizer 子类连贯地解决所有这些问题,现在我要编写自己的自定义多部分手势识别器。

但我宁愿不必——有没有更合适的方法来达到相同的结果?

I'm developing an iPhone/iPad app that supports dragging items between table views. Since all the tables don't fit on screen, I've written a custom UIScrollView that lays them out horizontally, and supports paging.

While I've gotten the primary drag and drop together, there are a few remaining issues I can't get past.

  1. After the user has selected an item to drag, and is dragging, they cannot scroll the UIScrollView to find the destination UITableView.

  2. Sometimes the user will want to drag the item within the same table view. But once the drag has begun, the table view no longer recognizes the scroll gesture.

I've tried a variety of different options, including implementing a UIGestureRecognizerDelegate and allowing multiple gesture recognizers to recognize gestures simultaneously.

The problem, as I see it stems from this description from the Event Handling Guide: "iOS recognizes one or more fingers touching the screen as part of a multitouch sequence. This sequence begins when the first finger touches down on the screen and ends when the last finger is lifted from the screen."

UIGestureRecognizer instances always match against the entire sequence. In my case, I want to split a single sequence down into discrete gestures -- some touches recognize a dragging of an item, while different touches within the same sequence should be recognized as a swipe or scroll gesture. Effectively, I want my gesture recognizers to recognize simultaneously, but only different touches. Once one recognizes a touch as part of a gesture, that touch should be ignored by the others.

I haven't found a way to solve all these issues coherently using the default UIGestureRecognizer subclasses, and am now about to write my own custom mutli-part gesture recognizer.

I'd rather not have to though -- is there any more appropriate way to achieve the same result?

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

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

发布评论

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

评论(1

半仙 2024-10-05 03:10:01

鉴于这里的沉默以及我刚刚找到的一篇博客文章,我相信答案是,不,没有办法使用标准框架进行子手势识别。

对于那些想要做类似事情的人,请查看此项目/博客文章,这是创建子手势识别库的尝试:

http://sunetos.com/items/2010/10/31/adding-subgestures-to-ios-gesture-recognition/

我还没有没有使用它——我最终手动制作了自己的迭代——但如果它成功的话,我会考虑重构以使用它。

Given the silence here, and a blog post I just found, I believe the answer is that, no there is no way to do sub-gesture recognition with the standard framework.

For those looking to do something similar, take a look at this project/blog post, which is an attempt to create a sub-gesture recognition library:

http://sunetos.com/items/2010/10/31/adding-subgestures-to-ios-gesture-recognition/

I haven't used it -- I ended up manually crafting my own iteractions -- but will consider refactoring to use it if it pans out.

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