Curtis Boylan
Curtis Boylan

Reputation: 827

iOS Pan Gestures

I am trying to instead of making my pan gesture spam the function when it pans, that it only plays the function once when the panning is finished, I have looked all online and fail to find a way to do this. Anyone got any solutions?

Current code below:

UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget: self  action:@selector(didPan:)];
self.mapView.gestureRecognizers = @[panRecognizer];

- (void) didPan:(UIPanGestureRecognizer*) gestureRecognizer
{
    NSLog(@"DID PAN");
}

Upvotes: 1

Views: 785

Answers (2)

Acharya Ronak
Acharya Ronak

Reputation: 41

ViewController.h

@property (strong, nonatomic) IBOutlet UIImageView *img;

ViewController.m

viewDidLoad

UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panDetected:)];

[_img addGestureRecognizer:panRecognizer];

Upvotes: 0

Tommy Devoy
Tommy Devoy

Reputation: 13549

- (void)panGestureDetected:(UIPanGestureRecognizer*)panGesture {

    if(panGesture.state == UIGestureRecognizerStateEnded){
        //do whatever
    }
}

Upvotes: 5

Related Questions