iOS – 手势识别器translationInView

我在平移手势识别器中使用以下代码行:

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

如果将关联的处理移动到长按手势识别器,则不存在translationInView方法。

我的问题是,如果使用长按识别器,我怎样才能获得相同的翻译价值?

谢谢

 CGPoint location = [recognizer locationInView:self.view]; 

对于UILongPressgestureRecognizerv它没有翻译的视图,它是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; } } 

希望它会帮助你。

感谢您的回复。 我真正想要的是translationInView的计算,它不同于locationInView。 我用下面的代码解决了这个问题:

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

它确实需要我跟踪起始位置,而我并不需要使用平移手势识别器,但它似乎运作良好。 我的代码的其余部分是围绕翻译而不是位置,所以我试图避免为了一致性而重写其他代码。

再次感谢您花时间回复。