Reordering UITableView without reorder control

前端 未结 5 1151
挽巷
挽巷 2020-12-10 03:17

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 ce

5条回答
  •  醉酒成梦
    2020-12-10 03:48

    I solved the question of the following steps:

    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.

提交回复
热议问题