view raw
Ahmed Z. Ahmed Z. - 5 months ago 36
iOS Question

Swipe Gesture calling the method multiple times

I have a small problem that em stuck on.. i have a Custom

, on its
i have added 2 gestures,
.. the tap gesture is working fine but the swipe gesture is calling the method multiple times.. some times calling it twice and some times even more than that… Here's how i have added them to the cell

//added in cellForRowAtIndexPath Method
UITapGestureRecognizer *tapToTranslate = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapToTranslate:)];
[tapToTranslate setNumberOfTapsRequired:1];
[tapToTranslate setNumberOfTouchesRequired:1];
tapToTranslate.delegate = self;
[cell.messageContentView addGestureRecognizer:tapToTranslate];

UISwipeGestureRecognizer *swipeToTranslate = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(translateTo:)];
swipeToTranslate.numberOfTouchesRequired = 1;
swipeToTranslate.direction = UISwipeGestureRecognizerDirectionLeft;
swipeToTranslate.delegate = self;
[cell.messageContentView addGestureRecognizer: swipeToTranslate];

These are there methods…

-(void)tapToTranslate:(UITapGestureRecognizer *)aGesture {}

-(void)translateTo:(UISwipeGestureRecognizer *)aGesture
aGesture.enabled = false;

I've tried to disable Swipe Gesture in its method after its called but that didn't help..

I've also have the
delegate method

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
return YES;

So Any help would be great…
thanks in advance…


<UITextView: 0x11322f700; frame = (18 10; 160.865 69.2656); text = '你怎么样? How are you doing?'; clipsToBounds = YES; gestureRecognizers = <NSArray: 0x11322fbd0>; layer = <CALayer: 0x11322fac0>; contentOffset: {0, 0}>


After Removing the gesture.delegate = self; line from both the gestures, the method started calling once as it was suppose to do. Apparently doing the job for me. So for anyone facing this issue, they can try removing the gesture's delegate and its method.