即使连接了硬件键盘也显示 iPhone 软键盘

Show iPhone soft keyboard even though a hardware keyboard is connected(即使连接了硬件键盘也显示 iPhone 软键盘)
本文介绍了即使连接了硬件键盘也显示 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 软键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to resize UITextView on iOS when a keyboard appears?(出现键盘时如何在iOS上调整UITextView的大小?)
UIKeyboardFrameBeginUserInfoKey amp; UIKeyboardFrameEndUserInfoKey(UIKeyboardFrameBeginUserInfoKey amp;UIKeyboardFrameEndUserInfoKey)
iPhone - Keyboard hides TextField(iPhone - 键盘隐藏文本字段)
iPhone / iOS : Presenting HTML 5 Keyboard for Postal Codes(iPhone/iOS:为邮政编码呈现 HTML 5 键盘)
UISearchbar clearButton forces the keyboard to appear(UISearchbar clearButton 强制键盘出现)
Display keyboard without animation(没有动画的显示键盘)