IOS - translationInView gesture recognizer

I use the following line of code in a gesture recognizer:

CGPoint translation = [sender translationInView:self.view]; 

If I transfer the associated processing to a long click gesture recognizer, there is no translInView method.

My question is, how can I get the same value for the translation if I use the long press recognizer?

thanks

+3
source share
2 answers
 CGPoint location = [recognizer locationInView:self.view]; 

For UILongPressgestureRecognizerv its not for translation, it's locationInView.

 -(void)handleLongPress:(UILongPressGestureRecognizer *)recognizer { CGPoint location = [recognizer locationInView:self.view]; switch (recognizer.state) { case UIGestureRecognizerStateBegan: break; case UIGestureRecognizerStateChanged: break; case UIGestureRecognizerStateEnded: break; default: break; } } 

Hope this helps you.

+2
source

Thanks for your reply. What I was really looking for was a calculation for translInView, which is different than locationInView. I solved this with the following code:

 CGPoint location = [sender locationInView:self.view]; CGPoint translation; translation.x = location.x - viewStartLocation.x; translation.y = location.y - viewStartLocation.y; 

This requires me to track the starting location, which I did not need to do with recognizing gestures, but it seems to work well. The rest of my code is centered around translation, not location, so I tried not to rewrite this other code just for the sake of consistency.

Thanks again for the time to respond.

+2
source

Source: https://habr.com/ru/post/954819/


All Articles