UITextView 不删除键盘

发布于 2024-08-20 09:54:25 字数 221 浏览 8 评论 0原文

问题,我的一个视图中有一个 UITextView,但是当用户按下 Enter 键时,键盘将被删除。我真的希望按 Enter 键输入 \n。这种情况发生在我的应用程序的其他几个地方。

很多帖子要求退货删除键盘,但没有说明如何保留它。

在 IB 中,我将返回键类型设置为“默认”。我还需要检查其他设置吗?

Question, I have a UITextView in one of my views, but when the user hits the Enter key, the keyboard is removed. I really want the Enter key to put in a \n. This happens in several other places in my app.

Lots of posts to have the return remove the keyboard, but nothing how to keep it.

In the IB, I have the return key type set to Default. Any other settings I need to check into?

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

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

发布评论

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

评论(2

流云如水 2024-08-27 09:54:25

默认情况下,UITextViewUITextField 都不会删除键盘。对于 UITextView 来说,这是因为用户可能确实想要输入换行符。如果你想删除键盘,你需要编写代码。

请参阅:

Neither UITextView nor UITextField won't remove the keyboard by default. For UITextView that's because the user may really want to enter a line-break. If you want to remove the keyboard you need to write code.

See:

最美的太阳 2024-08-27 09:54:25
(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
  // end editing and thus hide keyboard
  [textView resignFirstResponder];
  return YES;
}
(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
  // end editing and thus hide keyboard
  [textView resignFirstResponder];
  return YES;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文