开发者

How can I call a method when a key is typed?

开发者 https://www.devze.com 2023-03-05 20:33 出处:网络
Is there a way to call a method each time a user types on the onscreen keyboard?For example, a method is called when the user always hits the w key and a differe开发者_JAVA技巧nt method for the s key.

Is there a way to call a method each time a user types on the onscreen keyboard? For example, a method is called when the user always hits the w key and a differe开发者_JAVA技巧nt method for the s key. Or will I need to create my own keyboard for the user to use?

This will be for the iPad.


First create a subclass of UIResponder (e.g. a UIView or UIViewController) and have it adopt the UIKeyInput protocol (and implement the required methods). Then make it first responder. The method insertText: will be called for each key.

Caveat: Not all keyboards are supported (e.g. Japanese, Simplified Chinese).

0

精彩评论

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