I am trying to implement a UIPanGestureRecognizer for a UIImageView. Currently, I am able to drag the UIImageView and constrain where I move it to and that works. However, it’s moving what appears to be a copy of the UIImageView, and the original UIImageView is staying in place. Why would this occur?
After the UIImageView is created and added to the main view, I’m adding the gesture recognizers:
UIPanGestureRecognizer* pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(tileDragged:)];
pan.maximumNumberOfTouches = 1;
pan.minimumNumberOfTouches = 1;
[tileImageView addGestureRecognizer:pan];
Then in my tileDragged method:
case UIGestureRecognizerStateChanged:
{
PuzzleTileView *tileView = (PuzzleTileView *)[self.allTiles objectAtIndex:panGesture.view.tag];
CGFloat x = 0.0;
CGFloat y = 0.0;
// x and y are calculated.
[tileView setTransform:CGAffineTransformMakeTranslation(x, y)];
break;
}
It must be a simple issue where you have more than one image out there. Lots of us drag UIImageView’s around without incident. There’s nothing obvious in your code (though I’m confused by the different variable/class names), so you might need to give us a more comprehensive code sample. You might try adding some debugging messages (e.g. log a count of the subviews for your view at, say,
viewDidLoadand again in thetileDraggedmethod).I gather from your comments that you finally solved the problem. Congrats!