Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Jeremy1026

macrumors 68020
Original poster
Nov 3, 2007
2,216
1,030
So I have my UIImageView (named dot) which moves when a UITabBarButton is pressed. Then I have a touchesBegan event which when dot is pressed a label displays "Got It!". The touches work, sorta. When the image begins its animations the touch location on the screen is changed to the final location of dot as opposed to following along its translation path. How can I make the touch location follow the actual image as it makes it animation? Below is the code that I currently have, minus stuff that doesn't factor into this problem.

Code:
- (IBAction)moveDot {
	xmove = [[NSNumber numberWithInt:1 + arc4random() % 301] 
integerValue];
	xmove = xmove - 150;
	ymove = [[NSNumber numberWithInt:1 + arc4random() % 420] integerValue];
	ymove = ymove - 210;
	xcoor.text = [NSString stringWithFormat:@"X Coor: %i",xmove];
	ycoor.text = [NSString stringWithFormat:@"Y Coor: %i",ymove];
	[UIView beginAnimations:nil context:NULL];
	[UIView setAnimationDuration:2.0];
	dot.transform = CGAffineTransformMakeTranslation(xmove, ymove);
	[UIView commitAnimations];
	[NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(returnDot) userInfo:nil repeats:NO];
}

Code:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
	UITouch *touch = [touches anyObject];
	if (CGRectContainsPoint([dot frame], [touch locationInView:self])) {
		gotIt.text = [NSString stringWithFormat:@"Got It!"];
		
	}
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.