我有一个UITextField,它在其inputView中使用一个自定义的UIPickerView来将用户限制在几个选项上,其功能类似于下拉列表。当与通过蓝牙连接的硬件键盘一起使用时,硬件键盘会覆盖(并隐藏)我的inputView。然而,相关联的inputAccessoryView仍然存在。当按下我的硬件键盘上的“键盘”按钮(通常会显示普通UITextField的默认屏幕键盘)时,一切都按预期进行。(我的意思是我的inputView再次可见。)在iOS的早期版本(即7和更低版本)中,inputView在调用时总是可见的。
我暂时解决了这个问题,将UITextField的UIKeyboardType从UIKeyboardTypeDefault设置为UIKeyboardTypeTwitter,但只有在硬件键盘不被认为是特定UIKeyboardType的默认情况下才能工作。代码是pickerTextField.keyboardType = UIKeyboardTypeTwitter; (参见下面代码的大约2/3 )。经过进一步测试,这种部分解决方案几乎没有看上去那么有用。
在使用硬件键盘时,如何在所有情况下正确显示我的inputView?
相关代码片段:
-(int)setUpPickerWheelAtXLoc:(int)xLoc andYLoc:(int)yLoc {
int qwidth = width - (xLoc - FORMBORDERLEFT);
// Set up inputView (pickerView) to replace the keyboard
self.pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(xLoc, yLoc, qwidth, height)];
self.pickerView.delegate = self;
self.pickerView.dataSource = self;
self.pickerTextField = [[UITextField alloc] initWithFrame:CGRectMake(xLoc, yLoc, qwidth, 32)];
self.pickerTextField.delegate = self;
pickerTextField.borderStyle = UITextBorderStyleRoundedRect;
pickerTextField.layer.borderWidth = 0.3f;
pickerTextField.layer.borderColor = [[UIColor blackColor] CGColor];
pickerTextField.textColor = [UIColor blackColor];
pickerTextField.font = [UIFont systemFontOfSize:XXLARGEFONTSIZE];
pickerTextField.placeholder = @"Tap to choose from list...";
// Add pickerView as inputView
pickerTextField.inputView = self.pickerView;
pickerTextField.keyboardType = UIKeyboardTypeTwitter; // Suggested temporary solution
// Setup inputAccessoryView (Done button)
UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[doneButton addTarget:self action:@selector(pickerDoneButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[doneButton setTitle:@"Done" forState:UIControlStateNormal];
doneButton.titleLabel.font = [UIFont systemFontOfSize:XXLARGEFONTSIZE];
doneButton.frame = CGRectMake(0,0,100,44);
[doneButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
doneButton.contentEdgeInsets = UIEdgeInsetsMake(0,0,0,20);
doneButton.backgroundColor = [UIColor lightGrayColor];
pickerTextField.inputAccessoryView = doneButton;
return xLoc + qwidth;
}附加信息:在检查了其他几个地方之后,我已经确认至少在一个苹果产品中也发生了这种情况。(在8.0.2版iPhone 6上的“”应用程序/页面中)。参见月和日的出生日期。)
发布于 2014-10-21 14:53:34
苹果在iOS 8.1更新中解决了这个问题。
https://stackoverflow.com/questions/26128267
复制相似问题