Reputation: 11
I've managed to change views with UISwipeGestureRecognizer
but it only starts changing the view after I do the complete swipe. How can I make it start as soon as I start dragging my finger on the screen? I've searched but couldn't find an answer.
Upvotes: 1
Views: 83
Reputation: 903
GestureRecognizers will wait until it is certain which gesture was made. This is why they always have a bit of delay. One way of doing this otherwise is to implement your own swipe handler. E.g. You can use touchesBegan: touchesEnded: touchesMoved: and TouchesCancelled: -methods.
(Remember to enable these methods by enabling userInteractionEnabled property for your node(s))
// SKScene init
{
self.userInteractionEnabled = YES;
}
- (void) touchesBegan:(NSSet*) touches withEvent:(UIEvent*)event
{
// register that touch(es) began
}
- (void) touchesMoved:(NSSet*) touches withEvent:(UIEvent*)event
{
// Calculate which way touch(es) is/are moving
}
- (void) touchesEnded:(NSSet*) touches withEvent:(UIEvent*)event
{
// Register that touch(es) ended
}
Upvotes: -1
Reputation: 5681
Use a Pan gesture
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
[self addGestureRecognizer:pan];
Then do:
- (void)handlePan:(UIPanGestureRecognizer *)gesture {
CGPoint touchPoint = [gesture locationInView:YOUR_VIEW];
UIView *draggedView = [gesture view];
switch ([gesture state]) {
case UIGestureRecognizerStateBegan:
break;
case UIGestureRecognizerStatePossible:
break;
case UIGestureRecognizerStateChanged:
break;
case UIGestureRecognizerStateEnded:
break;
case UIGestureRecognizerStateCancelled:
break;
case UIGestureRecognizerStateFailed:
break;
default:
break;
}
}
Upvotes: 2