How to Suspend Touch Input

Dec 23, 2009   //   by Derek van Vliet   //   Development  //  No Comments

Have you ever encountered a situation where you wish you could just pause and resume touch input while developing an iPhone app? Sure, you could always increase the complexity of your input handling by considering the state of any number of variables, but there are some times when just switching input off and on would be easiest.

We had a number of cases like this when developing Addicus. In particular, because we have both the game and game over screens operating in a single cocos2d scene, we were noticing some bugs that occurred because of the way we handled input. This was solved by suspending input for brief periods of time.

Input Goes Off

Here’s how to tell your iPhone app to stop responding to touch events in just one line of code:

[[UIApplication sharedApplication] beginIgnoringInteractionEvents];

Input Goes On

And as you might expect, resuming responding to touch input events is similarly easy:

[[UIApplication sharedApplication] endIgnoringInteractionEvents];

Leave a comment

Our Games

Latest Tweets