I would like to create a pan gesture recognizer and attach it to a view.
The gesture should only take into consideration movement on one of the axises X or Y.
What I have so far is pretty crude
UIPanGestureRecognizer *recognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
[self addGestureRecognizer:recognizer];
-(void)handlePan:(UIPanGestureRecognizer *)recognizer
{
UIGestureRecognizerState state = recognizer.state;
CGPoint translation = [recognizer translationInView:self];
NSLog(@"state = %d : panned to %@",state,NSStringFromCGPoint(translation));
if ((recognizer.state == UIGestureRecognizerStateChanged) ||
(recognizer.state == UIGestureRecognizerStateEnded))
{
CGFloat translationX = translation.x;
if (ABS(translation.y) > 20 && ABS(translation.y) > ABS(translation.x))
{
// this is not a valid x pan because the vector has to much "y" movement in it
}
// need to do similar for x axis
}
}
Is there a better way to achieve this?