Conflicting Gesture Recognizers on UITableView

后端 未结 2 695
暗喜
暗喜 2020-12-19 18:25

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 ri

相关标签:
2条回答
  • 2020-12-19 18:41

    When I use UIGestureRecognizer on a UITableView, I met the same problem like u.Finally, I found the "cancelsTouchesInView" property in UIGestureRecognizer by this one,and its helpful.

      UIGestureRecognizer* tapGesture = [[UIGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
      **tapGesture.cancelsTouchesInView = NO;**//pass touch event to others
    

    best wishes!

    0 讨论(0)
  • 2020-12-19 18:46

    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:
    

    delegate method.

    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 {
           ...
        }
    }
    

    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.

    0 讨论(0)
提交回复
热议问题