I'm trying to create a sliding menu (kind of like in Facebook/Twitter apps) and my version successfully uses pan gestures for this effect. The class is called "SlideMenu".
I'm instantiating a SlideMenu in my ViewController, and then adding a bunch of UI elements as subviews on it, such as UISliders, UIButtons, etc.
The issue is that the pan gesture seems to interfere with the UISlider, as it will slide, but stop after a very short distance. I found a piece of code on an answer (Gesture problem: UISwipeGestureRecognizer + UISlider) however I am unsure on how to implement it or if it works with my design.
The code is this:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
if ([touch.view isKindOfClass:[UISlider class]]) {
// prevent recognizing touches on the slider
return NO;
}
return YES;
}
I tried adding it to my SliderMenu class and my ViewController, but no dice. Where does this go? What delegate do I have to set (if any?) Thanks
Basically, in whichever controller or view you are handling the gesture recognizer. When you create the gesture recognizer, you can set its delegate to some object (probably your view controller) and have this object implement the UIGestureRecognizerDelegate
. One of the delegate call-backs is gestureRecognizer:shouldReceiveTouch
, and so you just have to copy the code you placed above into your object's (view controller's) implementation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With