Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想在将内容输入 UITextView 后隐藏键盘,但默认情况下我不能像 UITextField 那样执行此操作。有没有办法隐藏键盘,现在我把可以帮助我的按钮放了。如果有任何默认的隐藏方式,请告诉我。
[textView resignFirstResponder];
这是你的详细答案
当用户输入“\n”(新行)表示按下“完成”或“返回”按钮时,使用以下代码从文本视图中隐藏键盘。
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text { if([text isEqualToString:@"\n"]) { [textView resignFirstResponder]; return NO; } return YES; }
示例 1和示例 2。