In my main viewcontroller, I have a uislider. and at the same time I assign UISwipeGestureRecognizer to the self.view as I want to detect gestures on the whole view.
The problem is whenever I slide the slider, the gesture recognizer captured it as well, and the slider behaviour is jerky and not nice.
Here is my code (gesture part)
UISwipeGestureRecognizer* singleSwipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeRight:)];
[singleSwipeRight setDirection:(UISwipeGestureRecognizerDirectionRight)];
singleSwipeRight.numberOfTouchesRequired = 1;
singleSwipeRight.delegate = self;
[self.view addGestureRecognizer: singleSwipeRight];
As I read in HERE, to prevent this, just implement the following delegate:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
if ([touch.view isKindOfClass:[UISlider class]]) {
// prevent recognizing touches on the slider
//NSLog(@"no");
return NO;
}
return YES;
}
But the funny thing is, this only work the 2nd time i slide the UISlider. The first time swipe ALWAYS goes to the gesturerecognizer handler.
Why? And how to solve this?
Thanks.