Reputation: 216
I need to get the imageView tags from touches moved.I have 10 imageviews and tags are from 1 to 10.I need to get the imageView tags when moved my finger over the images.
I can able to get this by,
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint location = [[touches anyObject] locationInView:self.view] ;
CGRect fingerRect = CGRectMake(location.x, location.y, 1, 1);
for(UIImageView *view in self.view.subviews)
{
CGRect subviewFrame = view.frame;
if(CGRectIntersectsRect(fingerRect, subviewFrame))
{
//we found the finally touched view
}
}
}
But i dont want to use for
loop. Is there any other alternate to get the imageView which is below my move?Any help would be greatly appreciated.
Thanks.
Upvotes: 0
Views: 49
Reputation: 13766
Use this:
UIView* touchedView = [self.view hitTest:location withEvent:nil];
With this location, you get a touchedView, in your case is UIImageView.
Upvotes: 1