how to add double tap gesture to UITextView

ios, uitapgesturerecognizer, uitextview

Solution

I have the solution on iOS6, we can use UIGestureRecognizerDelegate, and override gestureRecognizerShouldBegin: and gestureRecognizer:shouldReceiveTouch:. In this two method, we can check if the gesture is doubleTapGestureForZooming, if not return NO, or return YES. This works perfect in iOS6, but in iOS5 these two delegate method hasn't been called, so iOS5 may need another workaround. Finally, I get the workaround, we can override the addGestureRecognizer method of UITextView to remove default gesture, wish this will help somebody else.

PS: we really can't remove system gestures of UITextView, we even can't change their property. It seems when event happens, all gestures of UItextview will be added again.

Problem

currently I want to let UITextView to have a double tap gesture. It seems UITableView has its own double tap gesture, when we double tapped, some text will be selected. So I want to remove this default double tap gesture to my own gesture recognizer. I tried many methods, and all failed. It seems there's no way to remove the default recognizer of UITextView. I also want to add a transparent view on this UITextView to do double tap event, but this subview will block other gestures on UITextView. Is there some method to add double tap gesture recognizer to UITextView? I really hope there will be a work around. I am still expecting a work around of iOS5 :)

Original source

Related problems