UIView: how to check if strokes have ended in the same view in which they started

In AcaniUsersI created a grid of ThumbView : UIViewinstances inside UITableView. All thumbViewshave a width kThumbSize. How to determine if strokes have ended in the same view in which they started?

+5
source share
1 answer

The following works, but I'm not sure if this is the best way to do this. I think so.

Since everyone thumbViewshas a width kThumbSize, just check touchesEndedthat the x-coordinate of the locationInViewinstance UITouch(provided self.multipleTouchEnabled = NO) is less than or equal kThumbSize. This means that the strokes are completed inside thumbView. There is no need to check the y coordinate, because if touches are moved vertically tableView, containing thumbViews, scroll, and touches are canceled.

Do the following in ThumbView : UIView(whose instances are subzones a UITableView):

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"touchesEnded %@", touches);
    CGPoint touchPoint = [[touches anyObject] /* only one */ locationInView:self];
    if (touchPoint.x >= 0.0f && touchPoint.x <= kThumbSize) {
        [(ThumbsTableViewCell *)self.superview.superview thumbTouched:self];
    }
}

To register touches of only one thumbViewat a time, you also probably want to set self.exclusiveTouch = YES;in the initinstance method thumbView.

+2
source

All Articles