我想用蓝牙设备强制键盘打开

时间:2023-03-07
本文介绍了我想用蓝牙设备强制键盘打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个蓝牙条码设备.如果将蓝牙设备连接到 iPhone,我无法使用 iPhone 键盘写任何东西.你已经知道 iPhone 键盘不显示了,因为蓝牙设备是识别键盘.

I have a bluetooth barcode device. If connect the bluetooth device to the iPhone, I can't write anything using iPhone keyboard. you already know that IPhone keyboard does not show on, because the bluetooth device is recognized keyboard.

但是!!!当iphone连接蓝牙设备时,我必须通过键盘在文本框中写一些东西.

But!!! I have to write something by keyboard into the textbox while iphone connect with bluetooth device.

请告诉我该怎么做!:)谢谢~

Please Let me know how to do that! :) Thanks~

推荐答案

即使连接了蓝牙键盘,我们也可以显示设备虚拟键盘.为此,我们需要使用 inputAccessoryView.

We can show device virtual keyboard even when a bluetooth keyboard is connected. We need to use inputAccessoryView for that.

我们需要在 app delegate.h 中添加以下代码

We need to add below code in app delegate.h

@property (strong, nonatomic) UIView *inputAccessoryView;

delegate.m

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

当我们关注 textField 时,这将调用下面的方法.

This will call below method when we focus on a textField.

//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 bluetooth keyboard is attached.
-(void) textFieldBegan: (NSNotification *) theNotification
{

        UITextField *theTextField = [theNotification object];

        if (!inputAccessoryView) {
            inputAccessoryView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
            [inputAccessoryView setBackgroundColor:[UIColor lightGrayColor]];
        }

        theTextField.inputAccessoryView = inputAccessoryView;

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

forceKeyboard"的代码是,

and the code for "forceKeyboard" is,

-(void) forceKeyboard
{
    CGRect screenRect = [[UIScreen mainScreen] bounds];
    CGFloat screenWidth = screenRect.size.width;
    CGFloat screenHeight = screenRect.size.height;
    inputAccessoryView.superview.frame = CGRectMake(0, 420, screenHeight, 352);

}

这对我们来说很好.我们使用隐藏文本字段从蓝牙键盘获取输入,对于所有其他文本字段,我们使用设备虚拟键盘,使用 inputAccessoryView 显示.

This works fine for us. We use a hidden text field for getting input from bluetooth keyboard and for all other text fields we use device virtual keyboard which is displayed using inputAccessoryView.

如果这有帮助,如果您需要更多详细信息,请告诉我.

Please let me know if this helps and if you need any more details.

这篇关于我想用蓝牙设备强制键盘打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

上一篇:OnScreen 键盘在 Activity 启动时自动打开 下一篇:iOS:自定义键盘:我想将图像发送到 textDocumentProx

相关文章

最新文章