热门标签 | 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


推荐阅读
  • Apple iPad:过渡设备还是平板电脑?
    I’vebeenagonizingoverwhethertopostaniPadarticle.Applecertainlydon’tneedmorepublicityandthe ... [详细]
  • 本文介绍了iOS开发中检测和解决内存泄漏的方法,包括静态分析、使用instruments检查内存泄漏以及代码测试等。同时还介绍了最能挣钱的行业,包括互联网行业、娱乐行业、教育行业、智能行业和老年服务行业,并提供了选行业的技巧。 ... [详细]
  • 本文介绍了在iOS开发中使用UITextField实现字符限制的方法,包括利用代理方法和使用BNTextField-Limit库的实现策略。通过这些方法,开发者可以方便地限制UITextField的字符个数和输入规则。 ... [详细]
  • IhaveconfiguredanactionforaremotenotificationwhenitarrivestomyiOsapp.Iwanttwodiff ... [详细]
  • wpf+mvvm代码组织结构及实现方式
    本文介绍了wpf+mvvm代码组织结构的由来和实现方式。作者回顾了自己大学时期接触wpf开发和mvvm模式的经历,认为mvvm模式使得开发更加专注于业务且高效。与此同时,作者指出mvvm模式相较于mvc模式的优势。文章还提到了当没有mvvm时处理数据和UI交互的例子,以及前后端分离和组件化的概念。作者希望能够只关注原始数据结构,将数据交给UI自行改变,从而解放劳动力,避免加班。 ... [详细]
  • Yii framwork 应用小窍门
    Yiiframework应用小窍门1.YiiFramework]如何获取当前controller的名称?下面语句就可以获取当前控制器的名称了!Php代码 ... [详细]
  • 1.webkit内核中的一些私有的meta标签,这些meta标签在开发webapp时起到非常重要的作用(1) ... [详细]
  • 篇首语:本文由编程笔记#小编为大家整理,主要介绍了docker常用的命令总结相关的知识,希望对你有一定的参考价值。文章目录 ... [详细]
  • 我的iOS开发入门自学路径
    我有一个清单,列着希望在大学里完成的事。比如,学一门乐器,和朋友去旅游,搭建自己的博客,去滑翔,看各主题的书籍。其中一项是,写自己的App并且上架。去年开始,我准备完成这一项,所以 ... [详细]
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • 本文讨论了如何在不使用SearchBar display controller的情况下,单独使用SearchBar并捕获其textChange事件。作者介绍了实际状况,即左侧SliderMenu中的SearchBar需要在主页TableView中显示搜索结果。然后,作者提供了解决方案和步骤,帮助读者实现这一功能。 ... [详细]
  • 本文讨论了如何在codeigniter中识别来自angularjs的请求,并提供了两种方法的代码示例。作者尝试了$this->input->is_ajax_request()和自定义函数is_ajax(),但都没有成功。最后,作者展示了一个ajax请求的示例代码。 ... [详细]
  • 【shell】网络处理:判断IP是否在网段、两个ip是否同网段、IP地址范围、网段包含关系
    本文介绍了使用shell脚本判断IP是否在同一网段、判断IP地址是否在某个范围内、计算IP地址范围、判断网段之间的包含关系的方法和原理。通过对IP和掩码进行与计算,可以判断两个IP是否在同一网段。同时,还提供了一段用于验证IP地址的正则表达式和判断特殊IP地址的方法。 ... [详细]
  • PDO MySQL
    PDOMySQL如果文章有成千上万篇,该怎样保存?数据保存有多种方式,比如单机文件、单机数据库(SQLite)、网络数据库(MySQL、MariaDB)等等。根据项目来选择,做We ... [详细]
  • Android工程师面试准备及设计模式使用场景
    本文介绍了Android工程师面试准备的经验,包括面试流程和重点准备内容。同时,还介绍了建造者模式的使用场景,以及在Android开发中的具体应用。 ... [详细]
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社区 版权所有