I have a UIPanGestureRecognizer
I am using to track an object (UIImageView
) below a user\'s finger. I only care about motion on the X axis, and if
According to the documentation you can subclass you gesture recogniser:
In YourPanGestureRecognizer.m:
#import "YourPanGestureRecognizer.h"
@implementation YourPanGestureRecognizer
- (void) cancelGesture {
self.state=UIGestureRecognizerStateCancelled;
}
@end
In YourPanGestureRecognizer.h:
#import
#import
@interface NPPanGestureRecognizer: UIPanGestureRecognizer
- (void) cancelGesture;
@end
Now you can call if from anywhere
YourPanGestureRecognizer *panRecognizer = [[YourPanGestureRecognizer alloc] initWithTarget:self action:@selector(panMoved:)];
[self.view addGestureRecognizer:panRecognizer];
[...]
-(void) panMoved:(YourPanGestureRecognizer*)sender {
[sender cancelGesture]; // This will be called twice
}
Ref: https://developer.apple.com/documentation/uikit/uigesturerecognizer?language=objc