【问题标题】:2 touches problem2 触摸问题
【发布时间】:2010-10-15 19:25:06
【问题描述】:

最近我用这个代码来处理拖动触摸:

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

但是当用户同时触摸 2 个按钮时我的问题只有一个叫如何解决这个问题?

【问题讨论】:

  • 别忘了实现 touchCanceled:.

标签: objective-c ios


【解决方案1】:
【解决方案2】:

UIGestureRecognizer 易于实现,并且在触摸事件处理方面不易出错。 当按下第二个按钮时,可能会在 touchesBegan 、touchesMoved 或 touchesEnded 上输入按下事件,您必须在这些地方检查 [touches count]。但如果您想处理拖动行为,touchesMoved 是检查两次触摸或仅一次触摸的最佳位置。

正如 Eiko 所说,您应该实现touchedCanceled。 触摸事件的顺序可能是

  • touchedBegan->touchedMoved->touchedEnded->touchedCanceled,
  • 或touchedBegan -> touchMoved -> touchCanceled(没有touchedEnded)。

如果没有移动,则不会调用touchedMoved。这意味着触摸事件的顺序将是

  • touchedBegan->touchedEnded->touchedCanceled。
  • 或touchBegan->touchedCanceled。

【讨论】:

    【解决方案3】:

    感谢大家的回答,但在我的代码中,我使用了UITouch *t =[..];,如果我把它放在(UITouch *t in ... ) 的for循环中就可以了,所以当用户同时触摸两个手指时,该方法调用了两次

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-08-02
      • 2011-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多