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

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)
Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)
Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)
Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)
[ios.cocos2d+box2d]how to disable auto-rotation?([ios.cocos2d+box2d]如何禁用自动旋转?)