如何使用同一按钮隐藏和显示键盘
我有 UITextField
当应用程序启动时它成为FirstResponder
。然后,我有一个 UIButton
,按下它时 resignFirstResponder
。
如何用同一个按钮隐藏和显示键盘?是否可以?
I have UITextField
which becomeFirstResponder
when app starts. Then, I have a UIButton
which resignFirstResponder
when press it.
How to hide and show keyboard with same button? Is it possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据您的需求,以下代码应该具有相同的按钮,既隐藏又显示文本字段的键盘
edit
您还可以在 if 循环中输入代码来更改按钮的标题。放置更改按钮标题的代码的适当位置应位于 textField 的委托方法
-textFieldDidBeginEditing:
和-textFieldDidEndEditing:
中Based on what you seem to need, the following code should have the same button both hide and show the keyboard for the textField
edit
You can also put in code to alter the title of the button in the if loop.The appropriate place to put the code to alter the title of the button would in the textField's delegate methods
-textFieldDidBeginEditing:
and-textFieldDidEndEditing: