热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

即使连接了硬件键盘,也会显示iPhone软键盘-ShowiPhonesoftkeyboardeventhoughahardwarekeyboardisconnected

MyiPadappusesanexternaldevicethatactsasahardwarekeyboard.But,atsomepointinthese

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?

我的iPad应用程序使用外部“设备”充当硬件键盘。但是,在设置的某些时候,我需要输入文本而我不能使用“设备”(“设备”不是键盘)。那么,即使我连接了硬件键盘,有没有办法强制弹出软键盘?

4 个解决方案

#1


20  

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.

是。我们在一些应用程序中完成了这项工作,当用户将蓝牙扫描仪“键盘”与设备配对时。你可以做的是确保你的textField有一个inputAccessoryView,然后自己强制inputAccessoryView的框架。这将导致键盘显示在屏幕上。

We added the following two functions to our AppDelegate. The 'inputAccessoryView' variable is a UIView* we have declared in our app delegate:

我们在AppDelegate中添加了以下两个函数。 'inputAccessoryView'变量是我们在app delegate中声明的UIView *:

//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);
}

Then in our applicationDidFinishLaunching we added this notification observer so we would get an event anytime a text field began editing

然后在我们的applicationDidFinishLaunching中添加了这个通知观察器,这样我们就可以在文本字段开始编辑的任何时候获得一个事件

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

Hope that helps!

希望有所帮助!

#2


1  

There’s no way to do this with the current SDK. Please let Apple know via the Bug Reporter.

使用当前的SDK无法做到这一点。请通过Bug Reporter告知Apple。

#3


0  

Since I have the same problem, the closest solution I have found is to use Erica Sadun's app called KeysPlease which is available via cydia and modmyi. It's description is "Use soft kb even when connected to a BT kb.".

由于我遇到同样的问题,我发现最接近的解决方案是使用Erica Sadun的应用程序,名为KeysPlease,可以通过cydia和modmyi获得。它的描述是“即使连接到BT kb也使用软kb”。

Additionally I have found that if you have a physical keyboard also attached, in my case via the iPad keyboard doc, you can bring up the keyboard using a key which seems to map to the eject key on a bluetooth keyboard. Perhaps there is a way to inject this key as if it was pressed on an attached keyboard?

另外我发现如果你还有一个物理键盘,在我的情况下通过iPad键盘文档,你可以使用一个键来调出键盘,这个键似乎映射到蓝牙键盘上的弹出键。也许有一种方法可以注入这个键,好像它是在连接的键盘上按下的?

I really wish there was a more official coding solution to this.

我真的希望有一个更正式的编码解决方案。

#4


0  

When my app connect bluetooth device, keyboard wouldn't show.I try set force the frame of the inputAccessoryView as Brian Robbins say. It didn't work.

当我的应用程序连接蓝牙设备时,键盘将无法显示。我尝试设置强制inputAccessoryView的框架,如Brian Robbins所说。它没用。

Then I use a stupid way to solve.I found when I click textfield or textview one more time, keyboard will show. So I just need to simulate touch in textfield or textview once , it works.

然后我用一种愚蠢的方式来解决。我发现当我再次单击textfield或textview时,键盘会显示出来。所以我只需要在textfield或textview中模拟一次触摸即可。

If you want to do some simulate touch, check this. https://github.com/HUYU2048/PTFakeTouch

如果你想做一些模拟触摸,请检查一下。 https://github.com/HUYU2048/PTFakeTouch


推荐阅读
author-avatar
小丸子2502856277_253
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有