在 iPad 应用程序中检测蓝牙键盘

发布于 2025-01-06 05:09:39 字数 454 浏览 5 评论 0原文

在我的应用程序中,我有一个客户信息表单,其中有许多我使用过的文本字段,现在当用户编辑任何字段时,我需要将整个视图向上移动,以便编辑文本字段不会位于 iPad 的内部下方键盘,这工作正常。 现在客户想使用外部蓝牙键盘来填写此表格。一旦此外部键盘与 iPad 连接,则在应用程序中编辑任何文本字段时将不会显示内部键盘,因为外部已连接,在这种情况下,整个视图需要位于页面上,无需将其向上移动。 但是,当我编辑文本字段时,它仍然会上升,而不会在屏幕上显示内部键盘,并且当整个视图向上移动时,这会导致屏幕的一半空白。

为此,我尝试了一些方法,例如启用内部键盘显示/隐藏通知,但只有在未连接外部键盘时才会调用这些通知,这对我没有帮助。 还尝试过使用ExternalAccessory框架,但它不会检测到蓝牙连接的键盘也尝试过使用EADemo来检测外部键盘,但它没有检测到外部键盘,但它检测到信用卡刷卡器连接槽坞。

如果这里有人使用过此功能或知道与此相关的任何内容,请告诉我。

In my app I am having a customer info form on which there are a number of text fields I have used, now when a user edits any field I need to move whole view up so that the editing text field won't get under iPad's internal keyboard and this is working fine.
Now the client wants to use external Bluetooth keyboard for filling this form. Once this external keyboard is connected with iPad then in the app when editing any text field won't show internal keyboard as the external is connected and in this case whole view needs to be on the page and no need to move it up.
But when I edit text field it still goes up without showing internal keyboard on the screen and this leaves half of the screen blank as it moves whole view up.

For this I have tried some ways like enabling internal keyboard show/hide notifications but these notification only gets called when external keyboard is not connected and this is not helping me.
Also have tried with ExternalAccessory framework, but it wont detect the bluetooth connected keyboard also tried with EADemo to detect external keyboard and its not detecting external keyboard but it detects credit card swiper connected trough dock.

If anyone here has gone through this functionality or knows anything related with this, then please let me know.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

紅太極 2025-01-13 05:09:39

@SpySudhir -

逻辑A:

  • 在某个文件中有一个布尔变量,当键盘是外部或内部键盘时,它将返回是/否值。

  • 根据返回的bool值调用动画函数。

逻辑B:

  • 使用NSNotificationCenter监听键盘通知。

  • 像 will,show,hide 通知这样的通知会在它们上面放置一个 NSLog 并查看其中哪一个被调用。

  • 如果连接了外部板,则不会调用 willShow 方法。因此,在这种情况下,我们可以做一些解决方案,将 bool 值设置为 no,或者我们可以有一个计数器,每次检查它的值是否增加 1 或与此相同。

@SpySudhir --

Logic A:

  • have a bool variable in some file which will return yes/no value when the keyboard is external or internal.

  • On the basis of the bool value returned call the animation function.

Logic B:

  • Listen to the keyboard notification using NSNotificationCenter.

  • Notifications like will,show,hide notification put an NSLog over their and see which one of them is getting called.

  • If external board is connected the willShow method does not gets called. so in this case can we can do some work around and set the bool value to no or we can have a counter and check it every time if its value is increased by one or is same something like this.

乞讨 2025-01-13 05:09:39

当字段获得焦点时,您不应该向上移动视图 - 您应该只向上移动视图作为对 UIKeyboardDidShowNotification 的响应。系统会为您处理剩下的事情。

You should not move the view up when field gets focus - you should only move the view up as a response to a UIKeyboardDidShowNotification. The system takes care of the rest for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文