【问题标题】:How to implement a Drag and Drop ImageView in Cocoa-Touch?如何在 Cocoa-Touch 中实现拖放 ImageView?
【发布时间】:2012-04-20 14:25:27
【问题描述】:

我如何在我的应用程序中拖动图像(超过两个),因为它正在处理两个图像,但想在同一个视图中拖动大约 20 个图像

【问题讨论】:

  • 如何一次拖动 20 张图片?你应该多解释一点。
  • 我想在视图中放 20 张图像,用户可以移动任何图像拖放它

标签: ios drag-and-drop uiimageview


【解决方案1】:

最简单的方法是,为每个视图添加一个UIPanGestureRecognizer,它应该是可拖动的。

或者你可以写一个UIView-子类并覆盖TouchesBegan, TouchesMoved and TouchesEnded。因此,每个视图都会处理自己的拖动操作。

如果你想看一个例子,也许我的JDDroppableView 有帮助:
https://github.com/jaydee3/JDDroppableView

您也可以查看这些主题中的任何一个:
https://stackoverflow.com/search?q=drag+drop+ios

【讨论】:

  • 我已将此代码用于 2images -(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event{ UITouch touch =[[event all touches]anyObject]; CGPoint location =[touch locationInView:touch.view]; if([触摸视图]==image1) { image1.center=location ; } else if ([touch view]==image2) { image2.center=location ; } -(void)touchesMoved:(NSSet)touches withEvent:(UIEvent*)event{ [self touchesBegan:touches withEvent:event]; }
  • 如何为每张图片创建一个视图,这会在我的项目中造成很大的混乱
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多