我正在使用iPhone应用,我需要从UITableViewCell
中拖动图像
并将其放在tableview外的其他UIView
。
(imageview添加为:[cell.contentView addSubview:imageView])。
请帮我这个,任何有用的提示,示例代码?触摸事件委托不会触发,因为我将UIImageView添加到UITableViewCell。
答案 0 :(得分:1)
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