简体   繁体   English

UITextField隐藏键盘但Reamin First Responder?

[英]UITextField Hide Keyboard But Reamin First Responder?

I've subclassed a UITextField to display a UIDatePicker instead of a keyboard. 我已经将UITextField子类化为显示UIDatePicker而不是键盘。 Entering dates is something that happens often I our app. 输入日期经常发生在我的应用程序中。 The problem occurs when another of our custom classes that accommodates the keyboard needs to know what the first responder. 当另一个容纳键盘的自定义类需要知道第一个响应者是什么时,会出现问题。

Is there a way to remain first responder, whilst hiding keyboard? 有没有办法保留第一响应者,同时隐藏键盘?

No, you have to resign as responder (give up focus) to dismiss the keyboard. 不,你必须辞去响应者(放弃焦点)才能解雇键盘。

Edit: It seems I lied. 编辑:我似乎撒了谎。 Try [self.view endEditing:YES]; 试试[self.view endEditing:YES];
FYI: It only works on iOS 3.2+ 仅供参考:它仅适用于iOS 3.2+

Actually, instead of subclassing, you should just make a custom inputView for your text field which uses a date picker as the custom "keyboard". 实际上,您应该为文本字段创建一个自定义inputView,而不是子类,它使用日期选择器作为自定义“键盘”。 Then, it will remain the first responder and never even call the system keyboard in the first place. 然后,它将仍然是第一个响应者,甚至从不首先调用系统键盘。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM