我正在开发一个 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 中获取了这段代码
关于ios - 将图像从 UITableviewCell 拖放到其他 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14272268/