Skip to content

Instantly share code, notes, and snippets.

@jeffremer
Created January 3, 2013 19:28
Show Gist options
  • Save jeffremer/4446282 to your computer and use it in GitHub Desktop.
Save jeffremer/4446282 to your computer and use it in GitHub Desktop.
How to detect shake gestures in a UIViewController.
@implementation ViewController
#pragma mark - UIResponder
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
if (motion == UIEventSubtypeMotionShake) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Shaken"
message:@"Not stirred."
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
}
- (BOOL)canBecomeFirstResponder
{
return YES;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment