8

我有一个UITextField使用自定义UIPickerViewinputView限制用户使用几个选项的方法,其功能类似于下拉列表。当与通过蓝牙连接的硬件键盘一起使用时,硬件键盘会覆盖(并隐藏)我的inputView. 然而,相关的inputAccessoryView遗骸。当按下我的硬件键盘上的“键盘”按钮(通常会显示 vanilla 的默认屏幕键盘UITextField)时,一切都按预期工作。(我的意思是 myinputView再次可见。)在 iOS 的早期版本(即 7 及以下)中,inputView调用时始终可见。

我通过设置 from to 暂时解决了这个问题UITextFieldUIKeyboardType但这UIKeyboardTypeDefaultUIKeyboardTypeTwitter在硬件键盘未被识别为该特定键盘的默认设置时才有效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;
}

附加信息:在检查了其他几个地方后,我确认至少有一款 Apple 产品也发生了这种情况。(在 8.0.2 中的 iPhone 6 上的“创建新 Apple ID”应用程序/页面中。查看月份和日期的出生日期选择器视图。)

4

1 回答 1

0

Apple 在 iOS 8.1 更新中修复了该问题。

于 2014-10-21T14:53:34.133 回答