是否有办法捕获我的应用程序中的所有键盘事件?我需要知道用户是否在我的应用程序中使用键盘输入任何内容(应用程序有多个 View )。我能够通过子类化 UIWindow 来捕获 touchEvents,但无法捕获键盘事件。
最佳答案
使用 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 - 接收iPhone键盘事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1267560/