UITableView:将一行拖到另一行上 [英] UITableView: Drag a row onto another one
问题描述
我有一个表示对象列表的 UITableView,我希望用户触摸一个对象,将其拖到另一个对象上(以组合它们),然后看到两个对象消失并出现一个新对象.我想我不能用标准的表格视图编辑方法来做到这一点(不能将一行拖到另一行上,对吗?).我要写我的触摸听众吗?我该怎么做?
I have a UITableView that represents a list of objects, I'd like the user to touch an object, drag it onto another one (as to combine them) and seeing the two disappearing and a new one appearing. I guess that I can't do this with the standard table view editing methods (a row cannot be dragged onto another one, am I right?). Shall I write my touch listeners? how can I do that?
推荐答案
我设法找到了一个解决方法:在第一次单击自定义 UITableCellView 后,我创建了一个新的 UIView 放在窗口顶部,该窗口拦截了另一个触摸+拖动.
I managed to find a workaround: after the first click on a custom UITableCellView I create a new UIView to put on top of the window that intercepts another touch+drag.
另一个触摸会创建一个 UIImageView,它将未延迟单击的单元格复制为图像.这个 UIImageView 可以沿着 UIView 拖动,然后在必要时关闭.
The other touch creates a UIImageView that copies the undelying clicked cell as a Image. This UIImageView can be dragged around along the UIView and then dismissed when necessary.
当我结束触摸时,我会查看它是否以另一个单元格结束,如果是,我会获取它的 indexPath 并计算一个连贯的动作
When I end the touch I look if it ended up a another cell, if so I get its indexPath and compute a coherent action
这篇关于UITableView:将一行拖到另一行上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!