在调用gesturerecognizer的方法之前,是否存在我可以调用的任何方法?

时间:2012-03-12 08:39:06

标签: objective-c ios cocoa-touch

我有一个UIPanGestureRecognizer按钮。我想确定这样的手指方向:

if (sqrt(translation.x * translation.x) / sqrt(translation.y * translation.y) < 1)
    {
        isHorizontalScroll = YES;

    }
    else
    {
        isHorizontalScroll = NO;
    }

在调用识别器的方法之前。

有人知道解决方案吗?

3 个答案:

答案 0 :(得分:1)

使用touchesbegan,touchesmoved,touchesEnd

答案 1 :(得分:1)

嗯,当手势处于UIGestureRecognizerStateBegan状态时,听起来你应该在手势识别器中进行检查。例如:

- (void)handlePan:(UIGestureRecognizer *)sender {

    CGPoint translation = [(UIPanGestureRecognizer*)sender translationInView:self.view];    

    switch (sender.state) {

        case UIGestureRecognizerStateBegan:

            if (sqrt(translation.x * translation.x) / sqrt(translation.y * translation.y) < 1)
                isHorizontalScroll = YES;
            else
                isHorizontalScroll = NO;

            break;

        case UIGestureRecognizerStateChanged:

            ...

答案 2 :(得分:1)

实际上具体的实施取决于你。要做到这一点,你至少有3个杠杆:

  1. 使用手势识别器。
  2. 重新实现UIResponder的方法:

    – touchesBegan:withEvent:
    
    – touchesMoved:withEvent:
    
    – touchesEnded:withEvent:
    
  3. 重新实现UIWindow的方法:

    – (void)sendEvent:(UIEvent *)event
    
相关问题