iOS-手势识别器翻译 [英] iOS - Gesture Recognizer translationInView
问题描述
我在平移手势识别器中使用以下代码行:
I use the following line of code in a pan gesture recognizer:
CGPoint translation = [sender translationInView:self.view];
如果我将关联的处理移至长按手势识别器,则没有translationInView方法.
If I move the associated processing to a long press gesture recognizer, there is not a translationInView method.
我的问题是,如果使用长按识别器,如何获得相同的翻译价值?
My question is, how can I get the same value for translation if using the long-press recognizer?
谢谢
推荐答案
感谢您的答复.我真正要寻找的是translationInView的计算,这与locationInView不同.我用以下代码解决了这个问题:
Thanks for your reply. What I was really looking for was the computation for translationInView, which is different from locationInView. I resolved 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;
这确实需要我跟踪起始位置,这与平移手势识别器无关,但它似乎运行良好.我的其余代码以翻译而不是位置为中心,因此我试图避免为了保持一致性而不得不重写其他代码.
It does require me to track the starting location, which I didn't have to do with the pan gesture recognizer, but it seems to work well. The rest of my code is centered around the translation rather than the location, so I was trying to avoid having to rewrite that other code just for the sake of consistency.
再次感谢您抽出宝贵时间来答复.
Thanks again for taking time to reply.
这篇关于iOS-手势识别器翻译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!