ios - 防止硬件(蓝牙)键盘覆盖 iOS 8 中的 inputView

标签 ios ios8 inputview

我有一个 UITextField,它在其 inputView 中使用自定义 UIPickerView 来限制用户只能使用几个选项,其功能类似于下拉菜单列表。当与通过蓝牙连接的硬件键盘一起使用时,硬件键盘会覆盖(并隐藏)我的 inputView。但是,关联的 inputAccessoryView 仍然存在。当按下我的硬件键盘上的“键盘”按钮(通常会显示普通 UITextField 的默认屏幕键盘)时,一切都按预期进行。 (我的意思是我的 inputView 再次可见。)在以前的 iOS 版本(即 7 及以下版本)中,inputView 在调用时始终可见。

我通过将 UITextFieldUIKeyboardTypeUIKeyboardTypeDefault 设置为 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;
}

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

最佳答案

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

关于ios - 防止硬件(蓝牙)键盘覆盖 iOS 8 中的 inputView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26128267/

相关文章:

ios - CVOpenGLESTextureCacheCreateTextureFromImage 错误

ios - 使用 UIViewController 的 View 作为 UITextField 的 inputView 时抛出“UIViewControllerHierarchyInconsistency”

c++ - (cocos2d-x 3.2/xcode 6) 如何打开 iOS 的 cpp-tests,没有项目文件

ios - 关于 "to-many"和谓词

ios - [RCTContextExecutor dealloc] 中的 SIGABRT 每次重新加载

uitextfield - 如何设置自定义 inputView 的高度?

iOS8 - 应用程序恢复后 UIView inputView 消失

ios - 如果在其他类中实现,自定义点击识别器方法将不起作用

ios8 - iOS 8 照片框架 : Get a list of all albums with iOS8

ios - 应用程序启动时自动布局更改 View 的高度