2010/06/20

Shaking on the iPhone

Let’s say you have an iPhone application with many different View Controllers, and in some of them you want to detect a ‘Device Shake’ event. You can’t just catch it in the Controller itself, since it provide methods for that. So the solution is this – you subclass a UIWindow to detect an event and then broadcast it to your app. Then catch the event in appropriate places using NSNotificationCenter.

Don’t forget to change the parent class of your main Window to MotionWindow to catch the events.

Enjoy, here's the code:

 

No comments:

Post a Comment