Reputation: 1027
I am working on a iPhone app, where I need to drag an image from UITableViewCell
and drop it in some other UIView
outside the tableview.
(imageview added as :[cell.contentView addSubview:imageView]).
Please help me on this, any useful hint , sample code ?? Touch event delegates are not triggering since i am adding UIImageView to UITableViewCell.
Upvotes: 1
Views: 2608
Reputation: 9285
You will not get much event in UIImageView
so use UIButton
and try something like this to drag:
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;
}
when your center point match to other UIView
use [UIView adSubview:]
method to add UIButton in UIView
I have take this code from Basic Drag and Drop in iOS
Have a look at : Drag an Image within the Bounds of Superview
Upvotes: 1