时间:2010-07-24 17:49:34

标签: iphone cocoa-touch ipad uikit keyboard

5 个答案:

答案 0 :(得分:20)

是。我们已经在我们的一些应用程序中完成了这项工作,当用户将蓝牙扫描仪“键盘”与设备配对时。你可以做的是确保你的textField有一个inputAccessoryView,然后自己强制inputAccessoryView的框架。这将导致键盘显示在屏幕上。

我们在AppDelegate中添加了以下两个功能。 'inputAccessoryView'变量是我们在app delegate中声明的UIView *:

//This function responds to all textFieldBegan editing
// we need to add an accessory view and use that to force the keyboards frame
// this way the keyboard appears when the scanner is attached
-(void) textFieldBegan: (NSNotification *) theNotification
{
    UITextField *theTextField = [theNotification object];
    //  NSLog(@"textFieldBegan: %@", theTextField);

    if (!inputAccessoryView) {
        inputAccessoryView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, navigationController.view.frame.size.width, 1)];
    }

    theTextField.inputAccessoryView = inputAccessoryView;

    [self performSelector:@selector(forceKeyboard) withObject:nil afterDelay:0];
}

//Change the inputAccessoryView frame - this is correct for portrait, use a different
// frame for landscape
-(void) forceKeyboard
{
    inputAccessoryView.superview.frame = CGRectMake(0, 759, 768, 265);
}

然后在我们的applicationDidFinishLaunching中我们添加了这个通知观察者,这样我们就可以在文本字段开始编辑时随时获得一个事件

    //Setup the textFieldNotifications
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFieldBegan:) name:UITextFieldTextDidBeginEditingNotification object:nil];

希望有所帮助!

答案 1 :(得分:1)

使用当前的SDK无法做到这一点。请通过the Bug Reporter告知Apple。

答案 2 :(得分:0)

由于我遇到同样的问题,我找到的最接近的解决方案是使用Erica Sadun的名为KeysPlease的应用程序,该应用程序可通过cydia和modmyi获得。它的描述是“即使连接到BT kb也使用软kb”。

此外,我发现如果您还连接了物理键盘,在我的情况下通过iPad键盘文档,您可以使用一个键来调出键盘,该键似乎映射到蓝牙键盘上的弹出键。也许有一种方法可以注入这个键,好像它是在连接的键盘上按下的那样?

我真的希望有更正式的编码解决方案。

答案 3 :(得分:0)

当我的应用程序连接蓝牙设备时,键盘将无法显示。我尝试设置强制inputAccessoryView的框架,如Brian Robbins所说。它不起作用。

然后我用一种愚蠢的方式解决。我发现当我再次单击textfield或textview时,键盘会显示出来。 所以我只需要在textfield或textview中模拟一次触摸,它就可以了。

如果你想做一些模拟触摸,请检查一下。 https://github.com/HUYU2048/PTFakeTouch

答案 4 :(得分:0)

此处的解决方案在iOS 13上不起作用或与App Store不兼容,因此我通过创建自己的软键盘解决了该问题。这是很基本的,但是可以。随时贡献!

react-native-snap-carousel