Reputation: 659
I have a 2d-Grid of subviews. As I drag my finger along these subviews I want to call discrete method's per view such that for each view I hover above this method is called once. Logging out the results of the touches parameter it seems that only one view is referenced through the drag, namely the one that touchesbegan was on top of. How do I get the view for where my finger is currently dragging based on coordinates?
Upvotes: 1
Views: 129
Reputation: 10327
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
CGPoint touchLocation = [touch locationInView:self.contentView];
for (UIView *view in self.contentView.subviews)
{
if ([view isKindOfClass:[MyView class]] &&
CGRectContainsPoint(view.frame, touchLocation))
{
}
}
}
Ref: iOS - Detecting touches in a UIView?
Upvotes: 1