一旦UITextView成为iPhone SDK中的第一响应者,如何隐藏键盘?

发布于 2024-10-09 02:07:07 字数 153 浏览 0 评论 0原文

在我的 iPhone 应用程序中,当我单击 UITextView 键盘变得可见时,

我尝试在“textDidEndOnExit”事件上使用 resignFirstResponder 但键盘不会隐藏。

隐藏键盘应该怎么做?

请帮助和建议, 谢谢。

In my iPhone App when I click on UITextView keyboard becomes visible

I try to use resignFirstResponder on "textDidEndOnExit" event but the keyboard does not hide.

What should be done to hide the keyboard?

please Help and Suggest,
Thanks.

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

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

发布评论

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

评论(6

一生独一 2024-10-16 02:07:07

这是关于这个主题的另一个主题:
如何在空白区域时隐藏键盘触摸 iPhone

我想这可以帮助你。

Here another thread about this topic:
how to hide the keyboard when empty area is touched on iphone

i think this can help you.

梦在夏天 2024-10-16 02:07:07

我建议您在键盘上方保留一个工具栏和一个名为“关闭”的按钮。单击关闭按钮时,退出您的响应者并隐藏工具栏。在textView中textViewShouldBeginEditing显示工具栏。默认隐藏工具栏。alt text

I would suggest you to keep a toolbar and inside a button called "Dismiss" just above the keyboard. resign your responder and hide the toolbar when dismiss button is clicked. In the textView textViewShouldBeginEditing show the toolbar. Default hide the toolbar.alt text

故人的歌 2024-10-16 02:07:07

如果您希望 UITextView 不允许回车,并在用户按下返回键时关闭(或者如果您更改了返回键类型则完成),则实现 UITextViewDelegate 协议并使用类似以下内容:

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
  if ([text isEqualToString:@"\n"]) {
      [textView resignFirstResponder];
      return NO;
  }
  return YES;
}

If you want your UITextView to not allow carriage returns, and close when the user presses the return key (or Done if you have changed the return key type) then implement the UITextViewDelegate protocol and use something like:

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
  if ([text isEqualToString:@"\n"]) {
      [textView resignFirstResponder];
      return NO;
  }
  return YES;
}
佞臣 2024-10-16 02:07:07
   oneway, you can also hide keyboard when touch in view screen

 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
      UITouch * touch = [touches anyObject];
      if(touch.phase == UITouchPhaseBegan) {
      [txtDetail resignFirstResponder];
     }
  }
   oneway, you can also hide keyboard when touch in view screen

 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
      UITouch * touch = [touches anyObject];
      if(touch.phase == UITouchPhaseBegan) {
      [txtDetail resignFirstResponder];
     }
  }
千纸鹤带着心事 2024-10-16 02:07:07

创建一个 UIButton 或 UiBarButton 并为其分配一个方法,其中写入 [textView resignFirstResponder];

Make a UIButton or UiBarButton and assign it a method in which write [textView resignFirstResponder];

走走停停 2024-10-16 02:07:07
 - (BOOL)textViewShouldBeginEditing:(UITextView *)textView{


    return NO;
}

返回否;不会让你的键盘出现。希望它有帮助。你不需要任何工具栏或其他东西。尝试一下......

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


    return NO;
}

return No; wont allow your keyboard to appear.Hope it helps.You will not require any toolbar or something.Give it a try...

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