我如何让 UIKeyInput 进行重复的 deleteBackwards 调用
目前我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有简单的方法可以让系统键盘自动重复。这些给您留下了两个选择:
如果您只需要删除键来自动重复,则解决方案 1 效果很好,但如果您需要所有键来自动重复,则覆盖代码将变得与自定义键盘选项一样复杂。 (覆盖层需要每个键都有一个矩形,所以为什么不直接替换底层键盘)。
解决方案 2 涉及一定量的“前期”工作...您可以执行此操作的一种方法是定义键帽类(如物理键)和键盘布局类。
我已经在我从事的项目中实现了这两种解决方案,但我目前使用解决方案 2,因为我可以创建我喜欢的任何键盘。在简单的情况下,用户永远不需要知道它不是系统键盘。对于高级用户,他们可以根据需要自定义键盘。
不管怎样,我发现让键盘类变得愚蠢很有用;它只是传达一个键已转换为按下状态或已转换为打开状态。上面的附加类决定应采取什么操作。
在某些方面,我知道这不是您正在寻找的答案,但我希望它有所帮助,
工业区
There is no easy way to have the system keyboard do auto-repeat. These leaves you with two options:
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
我见过人们做的一件事就是在键盘按钮顶部放置一个假按钮。当有人按住它时,让计时器在每次触发时删除最后一个字母。
希望这有帮助。
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.