如何向 UITextView 添加双击手势 [英] how to add double tap gesture to UITextView

查看:34
本文介绍了如何向 UITextView 添加双击手势的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我想让 UITextView 有一个双击手势.似乎 UITableView 有自己的双击手势,当我们双击时,会选择一些文本.所以我想将这个默认的双击手势删除到我自己的手势识别器中.我尝试了很多方法,都失败了.似乎没有办法删除 UITextView 的默认识别器.我还想在这个 UITextView 上添加一个透明视图来执行双击事件,但是这个子视图会阻止 UITextView 上的其他手势.是否有一些方法可以将双击手势识别器添加到 UITextView?我真的希望会有一个解决方法.

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.

我仍然期待 iOS5 的解决 :)

I am still expecting a work around of iOS5 :)

推荐答案

我在iOS6上有解决方案,我们可以使用UIGestureRecognizerDelegate,并覆盖gestureRecognizerShouldBegin:和gestureRecognizer:shouldReceiveTouch:.在这两个方法中,我们可以检查手势是否为doubleTapGestureForZooming,如果不是返回NO,或者返回YES.这在 iOS6 中非常有效,但在 iOS5 中这两个委托方法没有被调用,因此 iOS5 可能需要另一种解决方法.最后,我找到了解决方法,我们可以覆盖 UITextView 的 addGestureRecognizer 方法以删除默认手势,希望这对其他人有所帮助.

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:UITextView 的系统手势我们真的不能去掉,我们甚至不能改变它们的属性.好像当事件发生时,UItextview 的所有手势都会重新添加.

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.

这篇关于如何向 UITextView 添加双击手势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆