Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to understand TranslationInView

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.

like image 485
S.J Avatar asked Dec 07 '14 20:12

S.J


1 Answers

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.

like image 142
MendyK Avatar answered Nov 03 '22 03:11

MendyK