For an iOS app I’m working on, all the images on the users device are displayed on one portion of the screen. The user should be able to drag those images to another portion of the screen to have them added to the set of images that will be used in the memory game.
Here’s a screenshot in case my explanation is hard to visualize

When the user drags the image, what I would like to have happen is a slightly smaller semi-transparent version of that image is created that they drag down to the bottom, but the original image stays there. I can spawn the new image just fine and even assign a target that moves the new image. The problem I’m running into is in order to drag the new image the user has to lift their finger off the screen and start dragging again. I would like the new image to take the old images drag event over. This is the code I have right now.
UIControl *mask = [[UIControl alloc]initWithFrame:frame];
[mask addSubview:img];
[mask addTarget:self action:@selector(dragExited:withEvent:) forControlEvents:UIControlEventTouchDragExit];
[scrImages addSubview:mask];
-(IBAction)dragExited:(id)sender withEvent:(UIEvent*)event
{
UIControl *control = sender;
[control resignFirstResponder];
UIImageView *img = [control.subviews objectAtIndex:0];
CGPoint point = [[[event allTouches]anyObject]locationInView:self.view];
UIControl *mask = [[UIControl alloc]initWithFrame:CGRectMake(0, 0, img.image.size.width, img.image.size.height)];
mask.center = point;
[mask addSubview:[[UIImageView alloc]initWithImage:img.image]];
[mask addTarget:mask action:@selector(removeFromSuperview) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:mask];
[mask addTarget:self action:@selector(thumbnailMoved:withEvent:) forControlEvents:UIControlEventTouchDragInside];
[mask touchesMoved:nil withEvent:nil];
}
-(IBAction)thumbnailMoved:(id)sender withEvent:(UIEvent*)event
{
UIControl *control = sender;
CGPoint point = [[[event allTouches]anyObject]locationInView:self.view];
control.center = point;
}
I tried to start the dragging process by calling [mask touchesMoved:nil withEvent:nil]; but that doesn’t seem to work. Any ideas?
I’m going to answer this with a different technique, pan gestures. I don’t use your technique, so I can’t speak to it, but I use the following all the time:
And then I have the handler:
You can also, rather than creating a new gesture recognizer for each image, just create one on the parent view, detect which image you’re over, and then carry on. That might look like:
And then: