试图了解TranslationInView

S.J*_*S.J 6 objective-c uitableview ios uipangesturerecognizer

在我的UITableViewCell子类中,我添加了一个平移手势,并且在gestureRecognizerShouldBegin我检查的方法中self.frame.origin.x,self.frame.origin.y两者都是0.000000 and 0.000000在应用后TranslationInView CGPoint translation = [gestureRecognizer translationInView:[self superview]];我得到了x=-4.000000 and y=0.000000

TranslationInView当我得到正确的单元格0.0和0.0的位置,因为第一个单元格将具有0.0和0.0,为什么我需要时,如何工作,我试图绕过它TranslationInView.

Men*_*dyK 10

TranslationInView是UIPanGestureRecognizer的一种方法,它可以告诉您自上次重置以来触摸的移动距离.当触摸发生故障或您自己重置时,它会重置.

例如

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

CGPoint的翻译增加/减少了手势移动的距离.