UIPanGestureRecognizer starting touch point

The UIPanGestureRecognizer is a very handy gesture recognizer. It gives us velocity, it had various states, and it can form the basis for some interesting interactions in your iOS applications. One thing it’s not very good at is telling the developer the initial touch location for a recognized pan operation.

By the time UIGestureRecognizerStateBegan is fired, the user’s finger has already moved a bit to actually trigger your delegate method. Depending on how fast the user moved the pan initially, that CGPoint could be fairly close or pretty far away from the actual starting position.

I have been working on a system that connects iOS devices and panning on a control application will affect the others in certain ways. And I needed to know the exact starting position even before the panning was recognized. Since I entered the convenient world of gesture recognizers in iOS I had nearly forgotten about touchesBegan, touchesMoved, and touchesEnded.

Pair the UIPanGestureRecognizer with touchesBegan and you’ll have exactly what you need. In my case I had an area to accept the touchesBegan from, so instead of using hitTest I did something like this which works very well:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    CGPoint locationPoint = [[touches anyObject] locationInView:self.view];
    CGPoint viewPoint = [trackPad convertPoint:locationPoint fromView:self.view];
    if([trackPad pointInside:viewPoint withEvent:event]){
        NSLog(@"--> %.2f", viewPoint.y);
    } else {
        NSLog(@"touched outside trackpad");


Related Posts Plugin for WordPress, Blogger..."UIPanGestureRecognizer starting touch point", 5 out of 5 based on 1 ratings.

Leave a Reply

Your email address will not be published. Required fields are marked *

× 3 = three

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>