开发者

how do i make UIKeyInput make repeated deleteBackwards calls

开发者 https://www.devze.com 2023-03-18 11:43 出处:网络
Currently I am using UIKeyinput but it is only sending a si开发者_如何学Gongle delteBackward event even when I hold down the delete key for a long time.

Currently I am using UIKeyinput but it is only sending a si开发者_如何学Gongle 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?


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号