【问题标题】:How can I cancel the code in touchesEnded when touchesBegan begins againtouchesBegan 再次开始时如何取消 touchesEnded 中的代码
【发布时间】:2014-12-21 02:04:04
【问题描述】:

我不知道这是否可能...我在 touchesEnded 中有这段代码:

[self performSelector:@selector(GameOver) withObject:nil afterDelay:3];

但是,如果您在 3 秒结束前再次触摸屏幕,我想取消调用 GameOver。知道我该怎么做。

在 touchesBegan 中,我尝试过这样的事情:

[NSObject cancelPreviousPerformRequestsWithTarget:self
                                         selector:@selector(touchesEnded:withEvent:)
                                           object:nil];

这不起作用。

【问题讨论】:

  • 这不是你之前问的同一个问题吗? stackoverflow.com/questions/27585523/…
  • 是的哈哈我只是想改写它,因为我决定我想采取一种单独的方法......不过我删除了那个。

标签: ios xcode touchesbegan


【解决方案1】:

您的selector 值在您的cancelPreviousPerformRequestsWithTarget 调用中是错误的,仅此而已。如果performSelector 中的原始选择器是GameOver,那么显然您要取消的执行请求必须指定为GameOver

这从文档中非常清楚:https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/index.html#//apple_ref/occ/clm/NSObject/cancelPreviousPerformRequestsWithTarget:selector:object:

【讨论】:

  • 请不要再用大写字母命名方法GameOver,好吗?它只是惹恼了青蛙。
  • 非常感谢。那解决了它!抱歉我的编码,我对此有点陌生。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-29
  • 1970-01-01
相关资源
最近更新 更多