【问题标题】:iOS 5.0 sendEvent called two [2] timesiOS 5.0 sendEvent 被调用了两次 [2] 次
【发布时间】:2012-05-14 06:06:31
【问题描述】:

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

【问题讨论】:

  • 那么,发送了哪些事件?这些信息会很有用......我想名字是 touchesBegan 和 touchesMoved。
  • 好吧,我触摸屏幕。据我了解,sendEvent/UIWindow 位于响应者链的根部。在任何其他视图可以将此事件获取到它自己的 touchesBegan 方法之前,该视图由 UIWindow hitTest 方法找到。所以我的触摸生成了 2 个 sendEvents.. 都找到了视图.. 但我不明白为什么我有 2 个由简单的触摸生成的事件。
  • 在方法中记录事件的名称,这应该可以帮助您获得更多信息。

标签: ios uiwindow


【解决方案1】:

出于调试目的,子类窗口(应用程序委托)并覆盖 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");
}

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

【讨论】:

  • 完全正确..因为没有意识到这一点而感到愚蠢..非常感谢。
【解决方案2】:

fingerDown 和 allFingersUp 调用 sendEvent

【讨论】:

    猜你喜欢
    • 2011-12-06
    • 2017-11-30
    • 2017-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-13
    • 1970-01-01
    相关资源
    最近更新 更多