我想迫使与蓝牙设备键盘 [英] I want to force keyboard on with bluetooth device

查看:237
本文介绍了我想迫使与蓝牙设备键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个蓝牙棒code设备。
如果蓝牙设备连接到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.

我们需要添加下面code在app delegate.h

We need to add below code in app delegate.h

@property (strong, nonatomic) UIView *inputAccessoryView;

下面添加通知中 - (BOOL)应用:(*的UIApplication)的应用didFinishLaunchingWithOptions:在(NSDictionary的*)launchOptions 方法的 delegate.m

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

这将调用下面的方法时,我们专注于文本框

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];
}

和code为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.

这篇关于我想迫使与蓝牙设备键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆