关闭数字键盘式键盘而不添加完成键
数字键盘上没有完成按钮。我不想添加自定义 Done 按钮,但如何关闭键盘?
There is no Done button on a Number Pad-type keyboard. I don't want to add a custom Done button, but how do I dismiss the keyboard?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以添加带有完成按钮(UIBarButtonItem)的UINavigationBar/UIToolBar,并在完成按钮的操作上设置textField/textView resignFirstResponder。
您可以将UINavigationBar/UIToolBar添加为textField/textView的inputAccessoryView。
编辑:可用性 iOS(3.2 及更高版本)
You could add a UINavigationBar/UIToolBar with a done button(a UIBarButtonItem), and make the textField/textView resignFirstResponder on the done button's action.
You can add the UINavigationBar/UIToolBar as inputAccessoryView of textField/textView.
Edit: Availability iOS (3.2 and later)
最简单的解决方案是在 UI 中的某处添加一个新按钮,点击时在
UITextField
(或其他内容)上调用resignFirstResponder
。在 iPhone 上将其放入工具栏会出现问题,因为工具栏通常位于屏幕底部并被键盘遮挡。稍微复杂一点的解决方案是在所有其他可点击 UI 元素后面放置一个不可见的
UIView
。现有 UI 未处理的任何点击都将转到此新视图,该视图可以在文本字段上调用 resignFirstResponder
。如果这些听起来都不吸引人,也许您应该扩展您的问题以包括您想要的行为类型。
The simplest solution is to add a new button somewhere in your UI that calls
resignFirstResponder
on yourUITextField
(or whatever) when tapped. Putting this in a toolbar is problematic on iPhone because toolbars are typically at the bottom of the screen and obscured by the keyboard.A slightly more complex solution is to put an invisible
UIView
behind all of your other tappable UI elements. Any taps not handled by your existing UI will go to this new view, which can callresignFirstResponder
on your text field.If neither of these sound appealing, perhaps you should expand your question to include the type of behavior you want.