In my code I have an array of objects which are UIImageViews with UIImages in them.
I use a for loop in -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event to move all objects from the array one by one.
Once they are moved to different positions on the main view I would like to be able to grab any of those objects and move them somewhere else.
I’m not sure how best to do this. Is there a way I can use touchesbegin so that I can drag only the item I clicked on?
Basically, there are five UIImageViews there now and each one has UIImage and I am trying to get to the point where when i click on any of them they are able to move around.
I’ve done something similar with great success using the
UIPanGestureRecognizerin my draggable view. To hook it up, it might look something like this:In your
pan:method, you could check the state of the gesture and even capture the gesture’s location and use it to relocate your view. Here’s a rough example of what it might look like:Here is more reading on the
UIPanGestureRecognizer.