获取 UITextView 中的触摸事件

发布于 2024-08-18 10:34:44 字数 129 浏览 2 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

东京女 2024-08-25 10:34:44

根据Apple文档,您可以为UITextView设置委托并实现UITextViewDelegate。

http://developer.apple.com/ iphone/library/documentation/UIKit/Reference/UITextViewDelegate_Protocol/Reference/UITextViewDelegate.html

具体来说,您可以通过实现 textViewShouldBeginEditing 来确定 UITextView 是否被触摸。

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView;

请务必在 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.

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView;

Be sure to set the delegate property on the UITextView in order to catch the event.

眼睛会笑 2024-08-25 10:34:44

只是想补充凯文的答案。 UITextView继承自UIScrollView。您应该获取文本视图的 UIScrollViewDelegate 协议中声明的所有事件。

我得到:

-(void)scrollViewDidScroll:(UIScrollView *)scrollView

当我将我的类声明为 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:

-(void)scrollViewDidScroll:(UIScrollView *)scrollView

when I declared my class as the delegate of UITextView.

花伊自在美 2024-08-25 10:34:44

创建自定义文本视图并在自定义类中提供触摸事件。然后您可以在该自定义类的委托中创建方法。

Create custom textview and provide touch events inside the custom class. then you can create methods in delegate of that custom class.

栩栩如生 2024-08-25 10:34:44

我用自己的逻辑解决了这个问题。

在阅读时,我们在 textview 上添加一个 Custom View 并使用这些方法:

(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

但是当我们处于编辑模式时,这就不再可能了。无论如何,我的要求只是在可读模式下。

感谢大家对解决问题的支持。

I resolved the issue by using my own logic.

While reading we are adding a Custom View over the textview and working with those methods:

(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文