Radislav
Radislav

Reputation: 2983

Does exists any method which I can call before gesturerecognizer's method will be called?

I have a button whith UIPanGestureRecognizer. I want to determine the direction of finger like this:

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

    }
    else
    {
        isHorizontalScroll = NO;
    }

before recognizer's method will be called.

Does anybody know the solution?

Upvotes: 0

Views: 102

Answers (3)

SVGreg
SVGreg

Reputation: 2368

Actually the concrete implementation is up to you. To do this you have at least 3 leverages:

  1. Use gesture recognizers.
  2. Reimplement UIResponder's methods:

    – touchesBegan:withEvent:
    
    – touchesMoved:withEvent:
    
    – touchesEnded:withEvent:
    
  3. Reimplement UIWindow's method:

    – (void)sendEvent:(UIEvent *)event
    

Upvotes: 1

tarmes
tarmes

Reputation: 15442

Hmm, it sounds like you should be doing that check in the gesture recognizer when the gesture is in the UIGestureRecognizerStateBegan state. For example:

- (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:

            ...

Upvotes: 1

Krrish
Krrish

Reputation: 2256

Use touchesbegan,touchesmoved, touchesEnd

Upvotes: 1

Related Questions