【问题标题】:iOS - Gesture Recognizer translationInViewiOS - 手势识别翻译InView
【发布时间】:2013-05-06 03:54:33
【问题描述】:

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

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

如果我将相关处理移至长按手势识别器,则没有 translateInView 方法。

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

谢谢

【问题讨论】:

    标签: ios uigesturerecognizer


    【解决方案1】:

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

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

    它确实需要我跟踪起始位置,这与平移手势识别器无关,但它似乎运行良好。我的其余代码以翻译而不是位置为中心,所以我试图避免为了一致性而重写其他代码。

    再次感谢您花时间回复。

    【讨论】:

      【解决方案2】:
      CGPoint location = [recognizer locationInView:self.view];
      

      对于 UILongPresgestureRecognizerv 它不是在视图中翻译,它是 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;
          }   
      }
      

      希望对你有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-07-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多