Skip to content

Instantly share code, notes, and snippets.

@mactive
Created October 25, 2012 09:58
Show Gist options
  • Save mactive/3951751 to your computer and use it in GitHub Desktop.
Save mactive/3951751 to your computer and use it in GitHub Desktop.
shake me 摇一摇
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
application.applicationSupportsShakeToEdit = YES;
}
shakeViewController.m
-(BOOL)canBecomeFirstResponder {
return YES;
}
-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self becomeFirstResponder];
}
- (void)viewWillDisappear:(BOOL)animated {
[self resignFirstResponder];
[super viewWillDisappear:animated];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
if (motion == UIEventSubtypeMotionShake)
{
// play sound
NSURL *audioPath = [[NSBundle mainBundle] URLForResource:@"message_3" withExtension:@"wav"];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)audioPath, &completeSound);
AudioServicesPlaySystemSound (completeSound);
[UIView animateWithDuration:0.7f animations:^
{
[self.shakeImageView setAlpha:0];
}
completion:^(BOOL finished)
{
[self.shakeImageView removeFromSuperview];
[self.view addSubview:self.afterView];
}
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment