views:

108

answers:

2

How do I enable the swipe gesture recognition for a UITextView?

This is my code and the event attach to it is not firing. It works for taps just not for swipes.

// Add swipe support for easy textview content clean up
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(eraseTextWithSwipe:)];
[targetContent addGestureRecognizer:swipe];
[swipe release];

How do I do that?

A: 

I found a solution that works well for me.

You need to set the delegate (referring to the code above)

swipe.delegate = self;

then you need to add a delegate to track multiple gestures, which will be able to track the swipe and the scrolling

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGesture
{
    yourTextbox.scrollEnabled = NO;
    return YES;
}

re-enable the scroll in the callback function (in the example above eraseTextWithSwipe)

amok
+1  A: 

Thank you. Your solution works. I just had to set the delegate and return YES in the mentioned delegate method. If not for usability reasons, you don't have to disable the scrolling on the UITextView.

blomeyer