拥有多个具有不同触摸的移动 UIImage 视图
我正在努力尝试让多个 UIImageView 在拖动时移动。我最初将所有运动都放在 TouchesBegan 下。但是,当我拖动单个对象时,它们都会消失,只有我拖动的对象会移动。
如何让每个图像都拖动自己的术语(我拖动第一个图像,只有第一个图像移动等)?
I am working on trying to get multiple UIImageViews to move when they are dragged. I was originally putting all the movement under TouchesBegan. However, when I drag a single object, they all disappear and only the one I am dragging moves.
How can I have each image dragged own its own terms(I drag the first image, only the first image moves etc.)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定这是否是您正在寻找的内容,但我不久前就从事过此工作,所以希望它有用。
只需确保在 XIB 文件中设置了 7 个 UIImageView,链接它们就可以了。
I'm not sure if this is what you're looking for but I worked on this a while ago, so hopefully it's useful.
Just make sure you set up 7 UIImageViews in the XIB File, link them and you'll be good to go.
您应该查看
UIPanGestureRecognizer
。在负责这些多个图像视图的视图控制器中,向每个图像视图添加平移手势识别器。视图控制器应该负责响应平移手势回调并相应地移动图像视图的框架。值得注意的是,您还应该获取图像视图中触摸相对于中心的偏移量并将其存储。然后,当平移视图时,您需要将偏移量考虑到计算中。这样,如果用户开始拖动远离中心点的某个位置,视图不会跳到用户的手指上。
请参阅 2010 年和 2011 年有关
UIScrollView
的 WWDC 会议视频。特别是从 2011 年开始。他们举例说明了如何做到这一点。You should look at
UIPanGestureRecognizer
. In the view controller that's responsible for these multiple image views, add a pan gesture recognizer to each of the image views. The view controller should be responsible for responding to the pan gesture callbacks and move the frame of the image view accordingly.Of note, you should also grab the offset of the touch within the image view from the center and store this. Then, when the view is panned, you need to factor in the offset into your calculations. This is so the view doesn't just jump to the user's finger if they start dragging somewhere distant from the center point.
See the WWDC session videos from 2010 and 2011 about
UIScrollView
. Especially from 2011. They go into examples of how to do some of this.我已经让它工作了!
但是,当一个图像与另一个图像碰撞时,它就消失了!
有人能解决这个问题吗?
I have gotten it to work!
But, When An Image Collides With Another, It Disappears!
Does anyone have a fix to this problem?