I am trying to build an app where I have multiple imageviews on the screen. The user needs to drag one of the images to answer a question. The problem is as the users drags the image down and goes over another image, the second images also begins to be dragged along with the first. How can I check to make sure only one image is moved at a time.
I started out with this
Code:
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
NSSet *allTouches = [event allTouches];
UITouch * touch = [[allTouches allObjects] objectAtIndex:0];
CGPoint location = [touch locationInView:self.view];
if (CGRectContainsPoint([myApple1 frame], location)) {
myApple1.center=CGPointMake(location.x,location.y);
}
if (CGRectContainsPoint([myApple2 frame], location)) {
myApple2.center=CGPointMake(location.x,location.y);
}
if(CGRectContainsPoint([myApple3 frame], location)) {
myApple3.center=CGPointMake(location.x,location.y);
}
}
also tried this:
Code:
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
NSSet *allTouches = [event allTouches];
UITouch * touch = [[allTouches allObjects] objectAtIndex:0];
CGPoint location = [touch locationInView:self.view];
if (CGRectContainsPoint([myApple1 frame], location)) {
myApple1.center=CGPointMake(location.x,location.y);
} else if (CGRectContainsPoint([myApple2 frame], location)) {
myApple2.center=CGPointMake(location.x,location.y);
} else if(CGRectContainsPoint([myApple3 frame], location)) {
myApple3.center=CGPointMake(location.x,location.y);
}
}
how can I make sure I only move one image at a time? Thank you for your help!