获取 UITextView 中的触摸事件
Apple 不为 UITextView
提供触摸事件处理。我正在开发的项目包含可读和可编辑的注释,并且我正在使用 UITextView
。请帮我解决这个问题——我怎样才能为我的项目获取触摸事件?
Apple does not provide touch event handling for UITextView
. The project I'm developing includes notes that can be readable and editable, and I am using a UITextView
. Please help me with this problem -- how can I get touch events for my project?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
根据Apple文档,您可以为UITextView设置委托并实现UITextViewDelegate。
http://developer.apple.com/ iphone/library/documentation/UIKit/Reference/UITextViewDelegate_Protocol/Reference/UITextViewDelegate.html
具体来说,您可以通过实现 textViewShouldBeginEditing 来确定 UITextView 是否被触摸。
请务必在 UITextView 上设置委托属性以便捕获事件。
According to the Apple documentation, you may set a delegate for UITextView and implement the UITextViewDelegate.
http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UITextViewDelegate_Protocol/Reference/UITextViewDelegate.html
Specifically, you can determine that a UITextView was touched by implementing textViewShouldBeginEditing.
Be sure to set the delegate property on the UITextView in order to catch the event.
只是想补充凯文的答案。 UITextView继承自UIScrollView。您应该获取文本视图的 UIScrollViewDelegate 协议中声明的所有事件。
我得到:
当我将我的类声明为 UITextView 的委托时。
Just wanted to add to Kevin's answer. UITextView inherits from UIScrollView. You should be getting all the events declared in UIScrollViewDelegate protocol for the text view.
I got:
when I declared my class as the delegate of UITextView.
创建自定义文本视图并在自定义类中提供触摸事件。然后您可以在该自定义类的委托中创建方法。
Create custom textview and provide touch events inside the custom class. then you can create methods in delegate of that custom class.
我用自己的逻辑解决了这个问题。
在阅读时,我们在
textview
上添加一个Custom View
并使用这些方法:但是当我们处于编辑模式时,这就不再可能了。无论如何,我的要求只是在可读模式下。
感谢大家对解决问题的支持。
I resolved the issue by using my own logic.
While reading we are adding a
Custom View
over thetextview
and working with those methods:But when we are in the editing mode it is not possible anymore. Anyhow my requirement is only in readable mode.
Thanks for all your support to resolve the issue.