在iOS中从uitableviewcell拖放到uiimage视图 [英] drag and drop from uitableviewcell to uiimage view in ios

查看:81
本文介绍了在iOS中从uitableviewcell拖放到uiimage视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助来实现拖放手势,我想知道您的意见以找到最佳方法.

I need help implementing a drag and drop gesture, I would like to know Your opinion to find the best approach.

我有一个视图控制器,其右侧有一个uitableview,左侧是一些图像视图.

I have a view controller with a uitableview on the right and some image views on the left.

我想允许用户将表格视图的每个单元格拖到其中一个图像视图上.基本上,如果未在其中一个图像视图上释放该单元格,则拖放操作将失败,否则该图像视图将根据所放置的单元格更改图像.

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.

谢谢

推荐答案

基本步骤如下:

  • 将长按手势识别器添加到表格视图(整个视图,而不是单个单元格)
  • 手势开始时,找到它位于哪个单元格上(转换点,然后使用indexPathForRowAtPoint获取该单元格)
  • 制作该单元格的副本,该副本将成为拖动视图(拍摄快照,将其添加到UIImageView并将其添加到主视图).或者,如果您不希望该视图看起来像该单元格,则可以使该视图看起来随意
  • 隐藏原始单元格,使其看起来像在被拖动
  • 更改手势后,根据手势的locationInView移动此图像视图的位置)
  • 手势结束时,检查单元格是否在图像上方(hitTest:为此),并执行所需的任何动画或计算.

这篇关于在iOS中从uitableviewcell拖放到uiimage视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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