如何强制 TouchesEnded
用户将游戏块(第 i 个图像视图)拖动到其目标位置。程序进行计数,发现所有项目都位于正确的位置,宣布“游戏结束”并将 userInteractionEnabled
设置为 NO。
很好,只是如果用户的手指仍然放在游戏棋子上,用户可能会意外地将棋子拖回目标区域之外。正在显示“游戏结束”,但该棋子不再位于正确的位置。
有没有办法强制touchesEnded(不检测touchesEnded),以便当棋子到达最终目的地时(有效)破坏与游戏棋子的接触(即,这样用户就不会意外地将其拉出位置) )?
userInteractionEnabled = NO
似乎要在触摸释放后才生效。
The user drags the game piece (the i-th image view) to its target location. The program counts, sees that all the items are in the correct places, announces "Game Over" and sets userInteractionEnabled
to NO.
Great, except that if the user's finger is still down on the game piece, the user can drag the piece back out of the target area by accident. "Game Over" is showing but the piece is no longer in the correct place.
Is there a way to force a touchesEnded (not detect a touchesEnded) so that the contact with the game piece is (effectively) broken when the piece is in its final destination (i.e. so that the user can't accidentally pull it out of position)?
userInteractionEnabled = NO
does not seem to take effect until the touch is released.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道有什么方法可以强制touchesEnded。
显然,处理此问题的一种方法是让您的应用程序保持指示游戏结束的状态,并防止在该状态下移动任何游戏块。
您可以尝试 beginIgnoringInteractionEvents,尽管我怀疑这是否能满足您的要求。我真的认为管理应用程序中的状态可以确保您做正确的事情,而不是在达到最终状态后移动该部分,这是正确的方法。
来自 Apple 的 iOS 事件处理指南:
I'm not aware of a way to force touchesEnded.
Obviously one way to handle this is for your application to maintain state that indicates that the game is over and guard against moving any game pieces when in that state.
You might try beginIgnoringInteractionEvents, though I doubt this will do what you are looking for. I really think managing state in your application that ensures that you will do the right thing, not moving the piece once the end state has been reached, is the way to go.
From Apple's Event Handling Guide for iOS:
我想在自己的应用程序中执行非常类似的操作后发现了这个问题。我希望在单击移动操作后立即运行
touchesEnded:
方法(如touchDown
操作方法),但不知道如何实现这一点。最后这就是我所做的并且有效! :这很完美!
I found this question after wanting to do a very similar action within my own application. I wanted the
touchesEnded:
method to be run immediately after clicking on the moving action (like atouchDown
action method), but did not know how to achieve this. In the end this is what I did and it WORKED! :This worked perfectly!