Trying to understand TranslationInView
Asked Answered
C

1

6

In my UITableViewCell subclass I add a pan gesture and in gestureRecognizerShouldBegin method I checked self.frame.origin.x and self.frame.origin.y both are 0.000000 and 0.000000and after applying TranslationInView CGPoint translation = [gestureRecognizer translationInView:[self superview]]; I am getting x=-4.000000 and y=0.000000

How TranslationInView work, I am trying to wrap my head around it, when I am getting the correct location of cell 0.0 and 0.0 because the first cell will have 0.0 and 0.0, why I need TranslationInView.

Chirography answered 7/12, 2014 at 20:2 Comment(0)
N
10

TranslationInView is a method of UIPanGestureRecognizer and it tells you how far the touch moved since it was last reset. It resets when the touch goes down or if you reset it yourself.

For example

- (void) pan: (UIPanGestureRecognizer *) recognizer
{
 if ((recognizer.state == UIGestureRecognizerStateChanged)||(recognizer.state ==    UIGestureRecognizerStateEnded)) {
    CGPoint translation = [recognizer translationInView:self];
    }
} 

The CGPoint traslation gets increased/decreased the distance that the gesture has moved.

Numbing answered 7/12, 2014 at 20:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.