Skip to content

Instantly share code, notes, and snippets.

@GuillaumeJasmin
Created March 26, 2015 09:16
Show Gist options
  • Save GuillaumeJasmin/5bc7e91b9b5d1e9ef4e6 to your computer and use it in GitHub Desktop.
Save GuillaumeJasmin/5bc7e91b9b5d1e9ef4e6 to your computer and use it in GitHub Desktop.
panGesture iOS
/**
* listener for pan gesture
*/
- (void)panListener
{
UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panHandler:)];
[self.view addGestureRecognizer:panGestureRecognizer];
}
/**
* trigger on touch move
*/
-(void)panHandler:(UIPanGestureRecognizer *)panGestureRecognizer
{
CGPoint touchLocation = [panGestureRecognizer locationInView:self.view];
// begin
if (panGestureRecognizer.state == UIGestureRecognizerStateBegan) {
NSLog(@"Begin touch");
NSLog(@"Begin pos x %f", touchLocation.x);
NSLog(@"Begin pos y %f", touchLocation.y);
} else if (panGestureRecognizer.state == UIGestureRecognizerStateEnded || panGestureRecognizer.state == UIGestureRecognizerStateFailed || panGestureRecognizer.state == UIGestureRecognizerStateCancelled) {
NSLog(@"end touch");
} else {
NSLog(@"current pos x %f", touchLocation.x);
NSLog(@"current pos y %f", touchLocation.y);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment