I want to get the current object touched in touchesMoved
. This is not to be confused with the touchLocation (CGPoint), but the actual object the user is touching. Using UITouch
always returns the initial touch (as it says in the apple docs) rather than the current or latest touch.
I have a grid of spots (UIImageViews
) that can be 3 by 3 up to 20 by 20.
As the user drags their finger on the screen a line is drawn that tracks the users finger. When a user intersects a gridspot the start point of the line snaps to that spot and continues to track the finger, Essentially allows you to draw shapes on a grid.
Currently i have a for loop that checks if the touchlocation intersects with a grid spot. This does work but is very slow for obvious reasons when their is 400 gridspots.
I have also tried Gesture recognizers but these cancel the touches.
Any help/advice will be much appreciated, thanks!
EDIT: this is what i have in my touchesMoved.
UITouch* touch = [touches anyObject];
CGPoint touchLocation =[touch locationInView:self];
for (int i=100; i<tagInt; i++) {
UIImageView *img=(UIImageView*)[self.view viewWithTag:i];
if (CGRectContainsPoint(img.frame, touchLocation)) {
//Drawing code setNeedsDisplay etc
}
}