iOS 5.0 sendEvent调用了两次[2]次

时间:2012-05-14 06:06:31

标签: ios uiwindow

我将UIWindow子类化,但由于某种原因, - (void)sendEvent:(UIEvent *)事件在与屏幕的任何交互中被调用2次。任何想法为什么会发生这种情况?

2 个答案:

答案 0 :(得分:2)

出于调试目的,子类窗口(app delegate)和覆盖sendEvent:方法

-(void) sendEvent:(UIEvent *)event
{
    NSLog(@"%@",event);
    [super sendEvent:event];
}

最有可能的是,您会注意到负责TouchesBegan和TouchesEnded(用于点击)的事件。这可以通过继承View和覆盖触摸相关方法来测试。

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"tocuhesBegan");
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"touchesMoved");
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"touchesEnded");
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"touchesCancelled");
}

此外,尝试在视图上拖动/滑动以注意发送到视图的事件数量的变化:)

答案 1 :(得分:0)

为fingerDown和allFingersUp

调用sendEvent