Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pan gesture interferes with UISlider

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

like image 432
user339946 Avatar asked Mar 07 '12 12:03

user339946


1 Answers

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.

like image 98
deleterOfWorlds Avatar answered Oct 17 '22 07:10

deleterOfWorlds