Pan手势干扰了UISlider [英] Pan gesture interferes with UISlider

查看:95
本文介绍了Pan手势干扰了UISlider的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个滑动菜单(有点像在Facebook / Twitter应用程序中),我的版本成功地使用平移手势来实现此效果。该类被称为SlideMenu。

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".

我在我的ViewController中实例化一个SlideMenu,然后在其上添加一组UI元素作为子视图,例如UISliders, UIButtons等

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.

问题是平移手势似乎会干扰UISlider,因为它会滑动,但会在很短的距离后停止。我在答案上找到了一段代码(手势问题:UISwipeGestureRecognizer + UISlider )但我不确定如何实现它或它是否适用于我的设计。

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.

代码如下:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    if ([touch.view isKindOfClass:[UISlider class]]) {
        // prevent recognizing touches on the slider
        return NO;
    }
    return YES;
}

我尝试将它添加到我的SliderMenu类和我的ViewController中,但没有骰子。这是怎么回事?我必须设置什么代表(如果有的话)?谢谢

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

推荐答案

基本上,无论你在哪个控制器或视图中处理手势识别器。创建手势识别器时,可以将其委托设置为某个对象(可能是视图控制器),并使此对象实现 UIGestureRecognizerDelegate 。其中一个委托回调是 gestureRecognizer:shouldReceiveTouch ,因此您只需将上面放置的代码复制到对象(视图控制器)的实现中。

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.

这篇关于Pan手势干扰了UISlider的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆