0

method触发基于Pan gesture价值的最佳方式是什么?

我想method在我pan location x介于 500 到 600 之间时触发。人们通常如何处理这个?

4

2 回答 2

0

You need to override gestureRecognizerShouldBegin. Then you can detect translation.x and see where the values fall between.

- (BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)panGestureRecognizer {
   CGPoint translation = [panGestureRecognizer translationInView:self.view];
   if (translation.x > 500 && translation.x < 600)
      [self callCustom];
   return true;
}

- (void) callCustom {
 //do what you need to do
}
于 2013-07-02T16:49:46.683 回答
0

我假设您有一个处理平移手势的方法。使该方法看起来像这样。

- (void)handlePan:(UIPanGestureRecognizer *)recognizer {

    if (recognizer.state == UIGestureRecognizerStateChanged) {

        CGPoint movement = [recognizer translationInView:self.view];

        if (movement.x >= 500 && movement.x <= 600) {

            [self methodToCall];
        }
    }
}
于 2013-07-02T16:53:46.603 回答