键盘可见时,将输入附件视图添加到UITextField [英] Adding input accessory view to UITextField while keyboard is visible
问题描述
我想将输入附件视图添加到 UITextField
,而它是第一个响应者,即显示键盘。显然,在此状态下将 UIView
分配给 inputAccessoryView
属性不会显示此视图。我必须首先关闭键盘并重新选择 UITextField
。
I would like to add an input accessory view to a UITextField
while it is the first responder, i.e. showing the keyboard. Apparently, assigning a UIView
to the inputAccessoryView
property in this state doesn't display this view. I have to first dismiss the keyboard and re-select the UITextField
.
有没有办法添加输入附件视图没有解雇和重新选择?
Is there a way to add an input accessory view without dismissing and re-selecting?
推荐答案
如果可能的话只分配 inputAccessoryView
一次。如果您需要进行自定义,并且只能确定在成为第一个响应者之前已经很晚,那么我仍然只会分配一次。但是在 UITextFieldDelegate
方法中自定义 inputAccessoryView
的子视图 textFieldShouldBeginEditing:
。像这样:
If possible only assign the inputAccessoryView
once. If you need it to be customized, and can only determine how very late just before becoming the first responder, then I would still only assign it once. But customize the subviews of the inputAccessoryView
in the UITextFieldDelegate
method textFieldShouldBeginEditing:
. Like so:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
[self setupInputAccessoryViewForTextField:textField];
return YES;
}
这篇关于键盘可见时,将输入附件视图添加到UITextField的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!