Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
969 views
in Technique[技术] by (71.8m points)

iphone - 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...