在UITableView上冲突的手势识别器 [英] Conflicting Gesture Recognizers on UITableView

查看:139
本文介绍了在UITableView上冲突的手势识别器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 UIView 上有两个自定义控件,一个是现在流行的滑动菜单(当你在 NavBar上滑动手指时视图向右滑动)另一个在 UITableViewCell 上 - 它是一个自定义 TableViewCell 来自名为 DMSlidingTableViewCell 的控件(如在 Twitter 应用程序中 - 当您在左侧滑动单元格时,它会显示一些按钮等)。

I have two custom controls on my UIView, the one is the now popular sliding menu (when you slide the finger on the NavBar the view slides to the right) and the other one is on the UITableViewCell - it's a custom TableViewCell from the control named DMSlidingTableViewCell (Like in Twitter app - when you slide the cell on the left, it reveals some buttons, etc.)

它们的工作正常,但是当我尝试在整个UITableView中添加一个Gesture识别器时,整个视图就成了 UIGestureRecognizer 的区域(所以当我移动它时,我可以将视图向右移动)手势识别器会以某种方式发生冲突。

They work just fine, but when I try to add a Gesture recognizer to the whole UITableView thus making the whole view a region for UIGestureRecognizer (so when I move it I can move the view to the right) the gestures recognizers somehow conflict.

这可能是什么原因?

推荐答案

我不清楚你认为两种滑动手势识别器在这种情况下可以一起工作的方式,但我想你可以尝试看看

I am not clear about the way you think that two swipe gesture recognizers could work together in that context, but I think you could try and give a look at the

– gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:

委托方法

请记住,你有2个手势,所以2个委托(从概念上讲,它们是通过相同的方法实现的),所以你可以制作一个手势(第一个参数)总是返回NO,另一个是YES,看看你是否可以让这两个手势识别器以令人满意的方式协同工作。

Keep in mind that you have 2 gestures, so 2 delegate (conceptually, they be implemented by the same method), so you could make one gesture (first argument) always return NO, the other YES and see if you can make the 2 gesture recognizers work together in a satisfactorily way.

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {

    if ([gestureRecognizer.view isKindOfClass:[UITableView class]]) {
       ...
    } else {
       ...
    }
}

这只是一个应该适用于你的情况的例子(虽然检查语法),但你也可以将2个识别器存储在你的类的属性中,这样你就知道哪个是哪个。

This is just an example which should work in your case (check the syntax, though), but you could also store the 2 recognizers in properties of your class, so you know which one is which.

这篇关于在UITableView上冲突的手势识别器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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