Search code examples
objective-cslideruigesturerecognizerjailbreakuser-interaction

Use a UIGestureRecognizer to get the coordinates whenever the finger moves?


I am trying to make a slider, where an image slides with the finger, left to right. I want to use a UIGestureRecognizer. How do I make it so it for this purpose, logs out the coordinates of the finger, every time the finger moves?


Solution

  • You can try something like this

    -(void)viewDidLoad;
    {
       [super viewDidLoad];
       UIPanGestureRecognizer* pgr = [[UIPanGestureRecognizer alloc] 
                                           initWithTarget:self
                                                   action:@selector(handlePan:)];
       [self.panningView addGestureRecognizer:pgr];
    
    }
    
    -(void)handlePan:(UIPanGestureRecognizer*)pgr;
    {
       if (pgr.state == UIGestureRecognizerStateChanged) {
          CGPoint center = pgr.view.center;
          imageView.center = center;
    
       }
    }