如何处理iPhone中的关键事件 [英] how to handle key events in iphone

查看:145
本文介绍了如何处理iPhone中的关键事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在开发iphone应用程序,想要在iphone中处理键盘事件。在Mac中,有一个类NSEvent可以处理键盘和鼠标事件,而在ios(iphone / ipad)中,NSEvent的对应物是UIEvent,它只处理触摸事件。我知道ios API不提供此功能,但我如何处理iphone中的关键事件?任何好的教程或者......开始......

Hi I am working on an iphone application and want to handle keyboard events in iphone. In Mac, there is a class NSEvent which handles both keyboard and mouse events, and in ios (iphone/ipad) the counterpart of NSEvent is UIEvent which handles only touch events. I know ios API does not provide this functionality, but how can i handle key events in iphone??? Any good tutorial or sth, to get started...

推荐答案

你无法直接编写keyboad代码; s键也没有在设备的情况下使用鼠标。

You cant directly code for keyboad;s key and there is no mouse in case of device.

您可以为不同类型的charectersets制作逻辑,或者您可以在textField delgate方法或Textview Delegates方法中制作逻辑

you can make your logics for different kind of charectersets or you can make your logics in textField delgate methods or Textview Delegates method

textView委托

textView delegate

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text

textField delegate

textField delegate

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string

您还可以对textField和Textview使用通知。

You can also use Notification for textField and Textview.

对于TextField,请使用此

For TextField use this

在viewDidLoad中调用此寄存器方法

call this register method in viewDidLoad

-(void)registerForTextFieldNotifications {

    NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];

    [notificationCenter addObserver:self
                           selector:@selector (handle_TextFieldTextChanged:)
                               name:UITextFieldTextDidChangeNotification
                             object:self.textField];

}


- (void) handle_TextFieldTextChanged:(id)notification {



    if([iSinAppObj.passCodeString isEqualToString:lockTextField.text])
    {   
        //code here
    }

}

对于文本视图,您只需更改此类活动名称

and for text view you need to change only event name like this

[notificationCenter addObserver:self
                               selector:@selector (handle_TextFieldTextChanged:)
                                   name:UITextViewTextDidChangeNotification
                                 object:self.textField];

这篇关于如何处理iPhone中的关键事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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