ios - 将图像从 UITableviewCell 拖放到其他 View

标签 ios objective-c cocoa-touch drag-and-drop

我正在开发一个 iPhone 应用程序,我需要从 UITableViewCell 中拖动图像
并将它放在 tableview 之外的其他一些 UIView 中。

( ImageView 添加为:[cell.contentView addSubview:imageView])。

请帮我解决这个问题,任何有用的提示,示例代码??触摸事件委托(delegate)未触发,因为我将 UIImageView 添加到 UITableViewCell。

最佳答案

您不会在 UIImageView 中获得太多事件,因此请使用 UIButton 并尝试像这样拖动:

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button addTarget:self action:@selector(imageTouch:withEvent:) forControlEvents:UIControlEventTouchDown];
[button addTarget:self action:@selector(imageMoved:withEvent:) forControlEvents:UIControlEventTouchDragInside];
[button setImage:[UIImage imageNamed:@"vehicle.png"] forState:UIControlStateNormal];
[self.view addSubview:button];

- (IBAction) imageMoved:(id) sender withEvent:(UIEvent *) event
{
    CGPoint point = [[[event allTouches] anyObject] locationInView:self.view];
    UIControl *control = sender;
    control.center = point;
}

当您的中心点与其他 UIView 匹配时,使用 [UIView adSubview:] 方法在 UIView 中添加 UIButton

我从 Basic Drag and Drop in iOS 中获取了这段代码

看看:Drag an Image within the Bounds of Superview

关于ios - 将图像从 UITableviewCell 拖放到其他 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14272268/

相关文章:

ios - Cocos2D setDisplayFrame View 更改后不起作用?

iphone - Dropbox 关闭 modalview Controller 不工作

ios - xcodebuild 成功时退出状态为 1

ios - Swipe Gesture 多次调用该方法

ios - 点击并按住以在 UILabel 中显示完整文本

ios - 如何以编程方式触发 UITableViewCell editActions?

iphone - UIImagePickerController内部的imagePickerController:didFinishPickingMediaWithInfo方法中的应用程序崩溃

ios - 如何正确继承 UITableViewController

ios - 跟踪 block 的异步连接

ios - iCarousel – 使所有项目都可选择,而不仅仅是居中的一个