Reputation: 2983
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
Reputation: 2368
Actually the concrete implementation is up to you. To do this you have at least 3 leverages:
Reimplement UIResponder's methods:
– touchesBegan:withEvent:
– touchesMoved:withEvent:
– touchesEnded:withEvent:
Reimplement UIWindow's method:
– (void)sendEvent:(UIEvent *)event
Upvotes: 1
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