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
1.1k views
in Technique[技术] by (71.8m points)

iphone - Conflicting Gesture Recognizers on UITableView

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

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.

What can be the reason here?

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

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.


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

...