我如何让 UIKeyInput 进行重复的 deleteBackwards 调用

发布于 2024-11-18 18:48:54 字数 92 浏览 1 评论 0原文

目前我正在使用 UIKeyinput,但即使我长时间按住删除键,它也只发送一个 delteBackward 事件。 当我长时间按住删除键时,如何让它向我发送多个事件调用?

Currently I am using UIKeyinput but it is only sending a single delteBackward event even when I hold down the delete key for a long time.
How can I make it send me multiple event calls when I hold delete down for a long time?

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

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

发布评论

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

评论(2

暗恋未遂 2024-11-25 18:48:54

没有简单的方法可以让系统键盘自动重复。这些给您留下了两个选择:

  1. 通过在键盘上使用覆盖来伪造它(请参阅@pho0的评论)
  2. 实现自定义键盘,将其安装为视图或视图控制器的inputView并实现支持自动重复的自定义协议。

如果您只需要删除键来自动重复,则解决方案 1 效果很好,但如果您需要所有键来自动重复,则覆盖代码将变得与自定义键盘选项一样复杂。 (覆盖层需要每个键都有一个矩形,所以为什么不直接替换底层键盘)。

解决方案 2 涉及一定量的“前期”工作...您可以执行此操作的一种方法是定义键帽类(如物理键)和键盘布局类。

我已经在我从事的项目中实现了这两种解决方案,但我目前使用解决方案 2,因为我可以创建我喜欢的任何键盘。在简单的情况下,用户永远不需要知道它不是系统键盘。对于高级用户,他们可以根据需要自定义键盘。

不管怎样,我发现让键盘类变得愚蠢很有用;它只是传达一个键已转换为按下状态或已转换为打开状态。上面的附加类决定应采取什么操作。

在某些方面,我知道这不是您正在寻找的答案,但我希望它有所帮助,
工业区

There is no easy way to have the system keyboard do auto-repeat. These leaves you with two options:

  1. Fake it by using an overlay on the keyboard (see the comment by @pho0)
  2. Implement a custom keyboard, install it as the inputView for your view or view controller and implement a custom protocol that supports auto-repeat.

Solution 1 works well if you only need the delete key to auto-repeat, but if you need all the keys to auto-repeat the overlay code becomes as complex as the custom keyboard option. (The overlay needs a rectangle for each key, so why not just replace the underlaying keyboard).

Solution 2 involves a certain amount of "up-front" work... One way you might do this is define a key cap class (like a physical key) and a keyboard layout class.

I have implemented both solutions in projects I have worked on, but I currently use solution 2 since I can create whatever keyboard I like. In the simple case the use need never know that it is not the system keyboard. For power users they can customize the keyboard as they see fit.

For what it is worth, I found it useful to have the keyboard class be dumb; it just communicates that a key has transitioned to being down or has transitioned to being up. An additional class above that decides what action should be taken.

In some ways, I know this is not the answer you were looking for, but I hope it helps,
IDZ

土豪我们做朋友吧 2024-11-25 18:48:54

我见过人们做的一件事就是在键盘按钮顶部放置一个假按钮。当有人按住它时,让计时器在每次触发时删除最后一个字母。

希望这有帮助。

One thing I've seen people do is put a fake button on top of the keyboard button. When someone is holding down on it, have a timer remove the last letter every time it fires.

Hope this helps.

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