重新排序UITableView,无需重新排序控制 [英] Reordering UITableView without reorder control

查看:93
本文介绍了重新排序UITableView,无需重新排序控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要用户能够以这种方式重新排序UITableView:他触摸一个单元格预定的时间(例如1秒),然后他可以拖放到其他单元格。

I need the user to be able to reorder a UITableView by this way: he touches a cell for a predetermined period (e.g. 1 second), then he can drag and drop it over the other cells.

我知道如何使用手势识别器实现长触摸检测,但是什么是实现拖放功能的最佳方式,而不使用重排控件(用户应该拖动单元格

I know how to implement the 'long touch' detection using a gesture recognizer, but what is the best way to implement the drag and drop ability without using a reorder control (the user should drag the cell from anywhere in the cell, not only from the reorder control)?

推荐答案

我解决了以下步骤的问题:

I solved the question of the following steps:


  1. 将手势识别器附加到UITableView。

  2. 检测由长触摸点击的单元格。此时创建选定单元格的快照,将其放到UIImageView并将其放在UITableView上。

  3. 存储所选单元格的索引,删除所选单元格并重新加载UITableView。
  4. $ b UIImageView的坐标应该相对于UITableView选择单元格$ b
  5. 禁用UITableView的滚动。现在你需要更改快照UIImageView的框架,当你将拖动单元​​格。您可以在 touchesMoved 方法中执行。

  6. 创建新单元格并在用户手指离开时重新加载UITableView

  1. Attach gesture recognizer to UITableView.
  2. Detect which cell was tapped by "long touch". At this moment create a snapshot of selected cell, put it to UIImageView and place it on the UITableView. UIImageView's coordinates should math selected cell relative to UITableView (snapshot of selected cell should overlay selected cell).
  3. Store index of selected cell, delete selected cell and reload UITableView.
  4. Disable scrolling for UITableView. Now you need to change frame of snapshot UIImageView when you will drag cell. You can do it in touchesMoved method.
  5. Create new cell and reload UITableView (you already have stored index) when the user finger leaves screen.
  6. Remove the snapshot UIImageView.

但是这样做并不容易。

But it was not easy to do it.

这篇关于重新排序UITableView,无需重新排序控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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