Search code examples
objective-cinvalidationtouchesmoved

How can I invalidate a touches moved method in Objective C?


I have a touchesmoved method that moves a ball depending on the position of the user's touch. How can I stop the ball from being dragged after the user gets a "Game Over".

Example - An NSTimer will be cancelled by calling [NSTimer invalidate]. How can I do that but with a touchesmoved method?


Solution

  • You could disable user interaction in the view: view.userInteractionEnabled = NO;

    That way the touchesMoved function would not be called, but would also disable any UI elements in that view.

    Another option is to have a BOOL gameOver variable, and in your touchesMoved function check the value, if it's true, return immediately and do nothing.