2013-05-05 71 views
3

我用下面的代码行中平移姿势识别器:的iOS - 姿势识别translationInView

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

如果我移动相关联的处理,以长按手势识别,不存在translationInView方法。

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

感谢

回答

2
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; 
    } 
} 

希望它能帮助你。

2

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

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

它要求我跟踪的起始位置,这是我没有与泛手势识别的事,但它似乎运作良好。我的代码的其余部分是围绕翻译而不是位置,所以我试图避免为了一致性而重写其他代码。

再次感谢您抽出时间回复。