【发布时间】:2012-04-10 15:40:02
【问题描述】:
我试图在不破坏其功能的情况下捕获 UIKeyboard 中的所有触摸事件。我试过了:
- 命中测试:
- UIGestureRecognizer
- 在顶部添加一个 UIWindow 并将事件传递给下一个响应者
但是,这些都不起作用。
而且似乎不允许我们对 UIKeyboard 进行子类化。
你能想到任何可行的方法吗?
谢谢,
高峰
更新:
让我们简化问题:如何添加一个 UIView 或 UIWindow 将特定的触摸事件传递给下一个响应者(就像将 userInteractionEnabled 设置为 NO)?
这是我的代码(当然不能工作...):
- (void)sendEvent:(UIEvent *)event {
NSLog(@"%@",event);
//if ([self eventIsNoteworthy:event]) [self extraEventHandling:event];
[super sendEvent:event]; // Apple says you must always call this!
}
-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
CGPoint hitPoint = [underneathButton convertPoint:point fromView:self];
if ([underneathButton pointInside:hitPoint withEvent:event]) return underneathButton;
NSLog(@"Called");
return [super hitTest:point withEvent:event];
//return mainWindow;
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@"Start");
[self.nextResponder touchesBegan:touches withEvent:event];
}
【问题讨论】:
-
当您说触摸事件时,您是指按下某些键的顺序吗?
-
@blake305 不,我是指触摸位置的CGPoints。
-
你现在想构建自己的键盘,展示它,让它将按下的字母传递给 textField,然后 NSLog CGPoints?
-
@AMayes 我可以构建自己的键盘,但我需要在这里使用系统键盘(不同的语言)。我只想要 CGPoints ;-)
标签: iphone objective-c ios keyboard touch