如何设置“用户交互启用”在代码中的 UITextViews 上

发布于 2024-08-04 00:30:28 字数 280 浏览 2 评论 0原文

我有以下问题:我有一个包含两个文本字段和一个 UITextView (不可编辑,但滚动)的视图来显示一些信息。当显示键盘时,我向上滑动整个视图,以便显示文本字段和键盘。当用户在文本字段之外单击时,我隐藏键盘并将视图移回下方。

仅当用户不单击 UITextView 来隐藏键盘时,此方法才有效。如果我在 IB 中打开“用户交互启用”,它可以工作,但 UITextView 将无法滚动。

如何在代码中设置“用户交互启用”,以便每当显示键盘时我都会禁用它?或者有更好的方法来解决这个问题吗?

蒂亚 斯特凡

I have the following problem: I got a view with two text fields and a UITextView (non editable, but scrolling) to show some infos. When the keyboard is shown I slide the whole view up so both text fields and the keyboard are shown. When the user clicks outside of the text fields I hide the keyboard and move the view back down.

This works only if the user does not click on the UITextView to hide the keyboard. If I turn of "User Interaction Enabled" in IB it works but UITextView won't be scrollable.

How do I set the "User Interaction Enabled" in code so whenever the keyboard is shown I would disable it? Or is there a better way to solve this?

tia
Stefan

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

☆獨立☆ 2024-08-11 00:30:28

设置 userInteractionEnabled 属性:

//UITextView *textView;
textView.userInteractionEnabled = YES;

Set the userInteractionEnabled property:

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