Created
November 18, 2013 11:53
-
-
Save douglashill/7526596 to your computer and use it in GitHub Desktop.
For detecting when an iOS device is shaken when the responder chain isn’t working for you. Handy for debugging. Subclass UIApplication, and pass in the new class name in UIApplicationMain().
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSString * const ShakeEventNotification = @"ShakeEventNotification"; | |
@implementation ShakeApplication | |
{ | |
BOOL _shakeStarted; | |
} | |
- (void)sendEvent:(UIEvent *)event | |
{ | |
[super sendEvent: event]; | |
if ([event subtype] == UIEventSubtypeMotionShake) { | |
// Shake events come in pairs. Only respond to the first. | |
if (_shakeStarted) { | |
_shakeStarted = NO; | |
} else { | |
_shakeStarted = YES; | |
[[NSNotificationCenter defaultCenter] postNotificationName:ShakeEventNotification object:self]; | |
} | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment