文本开始编辑后 UITextView 手势点击识别器不起作用 [英] UITextView gesture tap recognizer not working after text begins to edit

查看:20
本文介绍了文本开始编辑后 UITextView 手势点击识别器不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设置一个带有点击手势识别器的 UITextView,以便在点击 textView 后我可以做各种事情.对于其中之一,我希望文本视图在被点击后成为选定"视图,如下所示:

I am setting up a UITextView with a tap gesture recognizer so that I can do various things after the textView is tapped. For one I want the text view to be the "selected" view after it is tapped, like so:

selectedTextView = (UITextView *)recognizer.view;

它有效,除了在文本视图进入文本编辑模式后,陶醉键盘并允许文本编辑,此后我的自定义点击手势识别器不再工作.

It works, except that after the text view goes into text edit mode, reveling the keyboard and allowing text editing, thereafter my custom tap gesture recognizer no longer works.

有什么办法可以解决这个问题吗?

Any way around this?

推荐答案

您可能只需要为 -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer:(UIGestureRecognizer) 返回 YES*)otherGestureRecognizer 用于您的识别器.

You might just need to return YES for -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer for your recognizer.

看起来,当 UITextView 变成 firstResponder(键盘出现)时,Apple 的代码会从 UIView 中删除所有手势识别器代码>.您可以在 UITextViewDelegate–textViewDidBeginEditing: 中再次添加您的识别器.在退出 firstResponder 时,它似乎也删除了识别器,因此您还必须将其添加到 -textViewDidEndEnding:

It would appear that when the UITextView becomes the firstResponder (keyboard appears), that Apple's code removes all gesture recognizers from that UIView. You can add your recognizers again in UITextViewDelegate's –textViewDidBeginEditing:. It also appears to remove recognizers when resigning firstResponder so you'll have to also add it in -textViewDidEndEnding:

UITextFields 也是如此.

这篇关于文本开始编辑后 UITextView 手势点击识别器不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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