如何知道ios中UIKeyboard上按哪个键? [英] How to know which key is pressed on UIKeyboard in ios?

查看:75
本文介绍了如何知道ios中UIKeyboard上按哪个键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实施一个iPad应用程序。在我的应用程序中,我需要知道keyborad中按下了哪个键。你能帮助我吗?有没有办法找到它?

I am implementing a iPad application. In my application I need to know which key is pressed in the keyborad. Can you guys please help me is there any way to find it?

谢谢你,
Sekhar。

Thank you, Sekhar.

推荐答案

这是一个模糊的问题,但如果你只是想知道点击了哪个键,你需要实现一个委托用于调用键盘的输入控件。例如,如果您使用 UITextView ,然后实现 UITextViewDelegate ,将控件的委托属性连接到您的类,然后实现 textView:shouldChangeTextInRange:replacementText:。当 UITextView 识别出更改时,它将调用此方法。然后,您可以在replacementText参数中查看字符。

This is a vague question, but if you simply want to know what key has been tapped you need to implement a delegate for input control that called the keyboard. For example if you are using a UITextView, then implement the UITextViewDelegate, wire up the control's delegate property to you class, and then implement the textView:shouldChangeTextInRange:replacementText:. When UITextView recognizes a change then it will call this method. You can then watch for the characters in the "replacementText" argument.

使用 UITextField 使用 UITextFieldDelegate 并实现 textField:shouldChangeCharactersInRange:replacementString:方法。

你可以使用 UITextField 执行其他操作,例如将返回按钮更改为界面生成器中的完成按钮。实现 textFieldShouldReturn:方法。如果它被调用,则在传递给方法的对象上运行 resignFirstResponder

You can do other things with UITextField like change the Return button to a Done button in Interface Builder. The implement the textFieldShouldReturn: method. If it's called then run the resignFirstResponder on the object passed to the method.

希望这会有所帮助。

这篇关于如何知道ios中UIKeyboard上按哪个键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆