Show iPhone soft keyboard even though a hardware keyboard is connected(即使连接了硬件键盘也显示 iPhone 软键盘)
问题描述
我的 iPad 应用程序使用充当硬件键盘的外部设备".但是,在设置中的某些时候,我需要输入文本并且我不能使用设备"(设备"不是键盘).那么,即使我连接了硬件键盘,有没有办法强制弹出软键盘?
My iPad app uses an external "device" that acts as a hardware keyboard. But, at some point in the settings, I need to input text and I can't use the "device" ("device" is not a keyboard). So, is there any way to force pop the soft keyboard even thought I have a hardware keyboard connected?
推荐答案
是的.当用户将蓝牙扫描仪键盘"与设备配对时,我们已经在我们的一些应用程序中做到了这一点.你可以做的是确保你的 textField 有一个 inputAccessoryView,然后自己强制 inputAccessoryView 的框架.这将导致键盘显示在屏幕上.
Yes. We've done this in a few of our apps for when the user has a Bluetooth scanner "keyboard" paired with the device. What you can do is make sure your textField has an inputAccessoryView and then force the frame of the inputAccessoryView yourself. This will cause the keyboard to display on screen.
我们在 AppDelegate 中添加了以下两个函数.'inputAccessoryView' 变量是我们在应用委托中声明的 UIView*:
We added the following two functions to our AppDelegate. The 'inputAccessoryView' variable is a UIView* we have declared in our app delegate:
//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 中,我们添加了这个通知观察者,这样我们就可以在文本字段开始编辑时收到一个事件
Then in our applicationDidFinishLaunching we added this notification observer so we would get an event anytime a text field began editing
//Setup the textFieldNotifications
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFieldBegan:) name:UITextFieldTextDidBeginEditingNotification object:nil];
希望有帮助!
这篇关于即使连接了硬件键盘也显示 iPhone 软键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:即使连接了硬件键盘也显示 iPhone 软键盘
基础教程推荐
- 如何将多个组件添加到 PickerView? 2022-01-01
- Android:STATE_SELECTED不工作 2022-01-01
- 可可/目标C(OSX不是iOS)从子对象访问父对象 2022-01-01
- - (CGRect)convertRect:(CGRect)rect toView:(UIView *)view 如何工作 2022-01-01
- 在 iOS8 中无法获得正确的键盘高度值 2022-01-01
- 在 appComponent dagger 2 中动态添加测试模块? 2022-01-01
- 我的 UIImageView 的任务 2022-01-01
- 新的@SystemApi 注解是什么意思,和@hide 有什么区别 2022-01-01
- 在 Android 模拟器中激活网络位置提供程序? 2022-01-01
- 突出显示朗读文本(在 iPhone 的故事书类型应用程序中) 2022-01-01
