I want to force keyboard on with bluetooth device(我想用蓝牙设备强制键盘打开)
问题描述
我有一个蓝牙条码设备.如果将蓝牙设备连接到 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.
这篇关于我想用蓝牙设备强制键盘打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:我想用蓝牙设备强制键盘打开
基础教程推荐
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- iOS4 创建后台定时器 2022-01-01
