接收iPhone键盘事件 [英] Receive iPhone keyboard events

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

问题描述

总有没有在我的应用程序中捕获所有键盘事件的信息吗?我需要知道用户是否在应用程序中使用键盘输入了任何内容(应用程序具有多个视图).我可以通过将UIWindow子类化来捕获touchEvent,但是无法捕获键盘事件.

Is there anyway to trap all keyboard events across my application? I need to know if user is entering anything using keyboard across my application (Application has multiple views). I was able to capture touchEvents by subclassing UIWindow but unable to capture keyboard events.

推荐答案

使用NSNotificationCenter

Use NSNotificationCenter

[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(keyPressed:) name: UITextFieldTextDidChangeNotification object: nil];

[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(keyPressed:) name: UITextViewTextDidChangeNotification object: nil];

........

-(void) keyPressed: (NSNotification*) notification
{
  NSLog([[notification object]text]);
}

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

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