开发者

How to enable swipe gesture for a UITextView

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 r开发者_JAVA技巧elease];

How do I do that?


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)


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜