简体   繁体   English

在iOS中从uitableviewcell拖放到uiimage视图

[英]drag and drop from uitableviewcell to uiimage view in ios

I need help implementing a drag and drop gesture, I would like to know Your opinion to find the best approach. 我需要帮助来实现拖放手势,我想知道您的意见以找到最佳方法。

I have a view controller with a uitableview on the right and some image views on the left. 我有一个视图控制器,右边是uitableview,左边是一些图像视图。

I would like to allow the user to drag every cell of the table view on one of the image views. 我想允许用户将表格视图的每个单元格拖到其中一个图像视图上。 Basically the drag-n-drop will fail if the cell is not released on one of the image views, otherwise the image view will change image according to the dropped cell. 基本上,如果未在其中一个图像视图上释放单元格,则拖放操作将失败,否则图像视图将根据所放置的单元格更改图像。

What do You think is the best way to achieve this? 您认为实现此目标的最佳方法是什么?

In addition, when the user start dragging, I would like that he drags around a particular shaped subview, with image and data, not drag the semitransparent cell. 另外,当用户开始拖动时,我希望他拖动带有图像和数据的特定形状的子视图,而不是拖动半透明的单元格。

Thanks, 谢谢,

The basic steps for this would be: 基本步骤如下:

  • Add a long press gesture recognizer to your table view (the whole view, not individual cells) 将长按手势识别器添加到表格视图(整个视图,而不是单个单元格)
  • When the gesture begins, find which cell it is over (convert point, then user indexPathForRowAtPoint to get the cell) 手势开始时,找到它位于哪个单元格上(转换点,然后使用indexPathForRowAtPoint获取该单元格)
  • Make a copy of that cell which will become the dragged view (take a snapshot, add it to a UIImageView and add that to your main view). 制作该单元格的副本,该副本将成为拖动视图(拍摄快照,将其添加到UIImageView并将其添加到主视图)。 Or you could make the view look however you want if you dont want it to look like the cell 或者,如果您不希望视图看起来像单元格,则可以使视图看起来像您想要的那样
  • make your original cell hidden so it looks like it is being dragged 将您的原始单元格隐藏起来,使其看起来像在被拖动
  • On gesture changed, move teh position of this image view based on locationInView of the gesture) 更改手势后,根据手势的locationInView移动此图像视图的位置)
  • On gesture ended, check to see if the cell is over an image (hitTest: for this) and do any animations or calculations you need. 手势结束后,检查单元格是否在图像上方(hitTest:为此),并执行所需的任何动画或计算。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM