【问题标题】:Handling touches处理触摸
【发布时间】:2010-08-05 08:01:41
【问题描述】:

我有一个带有多个子视图的 UIView 子类,我想在类中处理这些事件:

  • touchesBegan:withEvent:
  • touchesMoved:withEvent:
  • touchesEnded:withEvent:

但我也希望在子视图中调用这些事件。我怎样才能做到这一点?

(我已经尝试过使用hitTest,但我只得到了touchesBegan事件并且没有使用该方法发送任何触摸)

【问题讨论】:

    标签: objective-c hittest touches touchesbegan touchesmoved


    【解决方案1】:

    我已经设法通过在主窗口中覆盖以下方法来解决它:

    - (void)sendEvent:(UIEvent*)anEvent
    

    我还通过 through 来检查它是否是正确的事件

    if ([[[anEvent allTouches] anyObject] phase] == UITouchPhaseBegan)
    

    我对@9​​87654323@ 和UITouchPhaseEnded 执行相同的操作,执行我的自定义代码,然后发送[super sendEvent:anEvent];

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-02-18
      • 2012-10-26
      • 2016-09-20
      • 2012-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多