1
votes

My table view has a text field above it. And whenever the text field is focussed, a swipe gesture is registered. When the swipe gesture is recognized, the keyboard is dismissed. The code is working for all gestures except for swipe up gesture is not working. This is my code

swipe = [[UISwipeGestureRecognizer alloc]
         initWithTarget:self action:@selector(dismissKeyboard)];

[swipe setDirection:UISwipeGestureRecognizerDirectionUp];

Can someone please let me know if there is any problem?

3
can you post a screenshot of what you are trying to do? - Nitin Alabur
Did you remember to add it to the UIView you want it to listen to using addGestureRecognizer? - Idles
@Idles - yes. As I told you already, only the up gesture is not working. I have tested it. - rahul
Well excuse me, but it's not in the code you posted. - Idles
What view is the swipe gesture added to? - Rey Gonzales

3 Answers

0
votes

if all the other gestures works, that means there is no logic problem. check out spelling errors. and reapply the swipe gesture, and check out everything (outlets etc.).

0
votes

I don't know about this case, but I know that when I've had gestures on a custom container view and then added a child view with its own gestures, I've had to iterate through the child's gestures and tell them to require my gestures to fail (i.e. mine take precedence). I've done this with scroll views successfully:

for (UIGestureRecognizer *gesture in self.scrollView.gestureRecognizers)
{
    [gesture requireGestureRecognizerToFail:myGesture];
}

The only times I've had problems with that are views like UITextView which remove and add gestures as you go in and out of edit mode, so that's a hassle.

Also, while I tried this with standard gestures, I've subsequently shifted to custom gestures that I've programmed to failed as quickly as possible (check the start location and fail immediately if it won't support the direction my gesture requires, rather than waiting for a bunch of touchesMoved to come to the same conclusion). If you don't want to interfere with the child view's gestures, be as aggressive as possible in letting yours fail. Maybe this isn't an issue with a swipe gesture, but it's a possible consideration if you find that your gestures end up changing the behavior of the child view noticeably.

But I suspect you'll probably just have to figure out which views have the gestures that are interfering with yours and make them require yours to fail first.

0
votes

Any chance you're colliding with one of the scrollview's gestures? It doesn't seem likely if your other gestures are working, but it might be worth at least trying the gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: method in the UIGestureRecognizerDelegate protocol.