iphone键盘触摸事件
我需要能够检测键盘上的触摸事件。我有一个应用程序,它显示一段时间不活动(即没有触摸事件)后出现的屏幕。为了解决这个问题,我对UIWindow进行了子类化,并实现了sendEvent函数,它允许我通过在一个地方实现该方法来获取整个应用程序上的触摸事件。除了显示键盘和用户在键盘上打字外,这一点在任何地方都适用。我需要知道的是,有没有一种方法可以检测键盘上的触摸事件,就像sentEvent对uiWindow所做的那样。提前感谢。找到了问题的解决方案。如果您观察到以下通知,则按键时可以获得一个事件。我在自定义uiwindow类中添加了这些通知,因此在一个位置执行该操作将允许我在整个应用程序中获取这些触摸事件iphone键盘触摸事件,iphone,sdk,uitouch,uikeyboard,uiwindow,Iphone,Sdk,Uitouch,Uikeyboard,Uiwindow,我需要能够检测键盘上的触摸事件。我有一个应用程序,它显示一段时间不活动(即没有触摸事件)后出现的屏幕。为了解决这个问题,我对UIWindow进行了子类化,并实现了sendEvent函数,它允许我通过在一个地方实现该方法来获取整个应用程序上的触摸事件。除了显示键盘和用户在键盘上打字外,这一点在任何地方都适用。我需要知道的是,有没有一种方法可以检测键盘上的触摸事件,就像sentEvent对uiWindow所做的那样。提前感谢。找到了问题的解决方案。如果您观察到以下通知,则按键时可以获得一个事件。我在
[[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
{ [self resetIdleTimer]; }
无论如何,希望它能帮助其他人。iPhoneDev:以下是我正在做的 我有一个自定义的UIWindow对象。在这个对象中,有一个NSTimer,只要有一次触摸,它就会被重置。要获得此触摸,必须覆盖UIWindow的sendEvent方法 这是我的自定义窗口类中sendEvent方法的外观:
- (void)sendEvent:(UIEvent *)event
{
if([super respondsToSelector: @selector(sendEvent:)])
{
[super sendEvent:event];
}
else
{
NSLog(@"%@", @"CUSTOM_Window super does NOT respond to selector sendEvent:!");
ASSERT(false);
}
// Only want to reset the timer on a Began touch or an Ended touch, to reduce the number of timer resets.
NSSet *allTouches = [event allTouches];
if ([allTouches count] > 0)
{
// anyObject works here.
UITouchPhase phase = ((UITouch *)[allTouches anyObject]).phase;
if (phase == UITouchPhaseBegan || phase == UITouchPhaseEnded)
{
[self resetIdleTimer];
}
}
}
以下是resetIdleTimer:
- (void)resetIdleTimer
{
if (self.idleTimer)
{
[self.idleTimer invalidate];
}
self.idleTimer = [NSTimer scheduledTimerWithTimeInterval:PASSWORD_TIMEOUT_INTERVAL target:self selector:@selector(idleTimerExceeded) userInfo:nil repeats:NO];
}
在此之后,在IDletimerExcepended中,我向窗口代理(在本例中为appDelegate)发送一条消息
在appDelegate中创建此自定义窗口对象时,我将appDelegate设置为此窗口的委托。在appDelegate中,idletimemitexceedd的定义是在计时器过期时我必须做的事情。关键是创建自定义窗口并重写sendEvent函数。结合上面我在自定义窗口类的init方法中添加的两个键盘通知,您应该能够在应用程序的任何地方获得屏幕上所有触摸事件的99% 你可以发布检查屏幕是否处于非活动状态的代码吗。我也在这样做。只是想知道RU使用appdelegate上的计时器检查用户是否处于活动状态。。。
- (void)idleTimerExceeded
{
[MY_CUSTOM_WINDOW_Delegate idleTimeLimitExceeded];
}