我遇到了一个问题,当在一个 UITextField 或 UITextView 中留下键盘时,键盘不会被解雇 UIModalPresentationFormSheet 。另外,我创建了一个大按钮作为视图的背景,因此如果用户点击字段之外它会被触发。我在常规视图控制器中使用相同的代码,它按预期工作。在模态视图控制器中它什么都不做。任何建议都将不胜感激。
I am running into an issue where the keyboard does not get dismissed when leaving a UITextField or UITextView in a UIModalPresentationFormSheet. In addition, I've created a large button to serve as the view's background so if the user taps outside the fields it gets triggered. I am using the same code in a regular view controller, and it works as expected. In the modal view controller it does nothing. Any suggestions would be appreciated.
- (BOOL)textFieldShouldReturn:(id)sender { [titleTextField resignFirstResponder]; return YES; } - (BOOL)textViewShouldReturn:(id)sender { [synopsisTextView resignFirstResponder]; return YES; } - (IBAction)textFieldDoneEditing:(id)sender { [sender resignFirstResponder]; } - (IBAction)textViewDoneEditing:(id)sender { [sender resignFirstResponder]; } - (IBAction)backgroundClick:(id)sender { [titleTextField resignFirstResponder]; [synopsisTextView resignFirstResponder]; }推荐答案
覆盖 disablesAutomaticKeyboardDismissal 返回NO,如下所示修复了我的同样问题。您应该将此代码放入视图控制器,从中启动键盘:
Overriding disablesAutomaticKeyboardDismissal to return NO as below fixed the same problem of mine. You should put this code to your view controller, from which you initiate the keyboard:
- (BOOL)disablesAutomaticKeyboardDismissal { return NO; }另外,请检查 SO 问题,如果你想得到详细的解释。
Also, check this SO question if you want to get a detailed explanation.
更多推荐
模态对话框不会关闭键盘
发布评论