首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >防止硬件(蓝牙)键盘在inputView 8中重写iOS

防止硬件(蓝牙)键盘在inputView 8中重写iOS
EN

Stack Overflow用户
提问于 2014-09-30 19:07:20
回答 1查看 745关注 0票数 8

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

我暂时解决了这个问题,将UITextFieldUIKeyboardTypeUIKeyboardTypeDefault设置为UIKeyboardTypeTwitter,但只有在硬件键盘不被认为是特定UIKeyboardType的默认情况下才能工作。代码是pickerTextField.keyboardType = UIKeyboardTypeTwitter; (参见下面代码的大约2/3 )。经过进一步测试,这种部分解决方案几乎没有看上去那么有用。

在使用硬件键盘时,如何在所有情况下正确显示我的inputView

相关代码片段:

代码语言:javascript
复制
-(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上的“”应用程序/页面中)。参见月和日的出生日期。)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-10-21 14:53:34

苹果在iOS 8.1更新中解决了这个问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26128267

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档