Created
October 25, 2012 09:58
-
-
Save mactive/3951751 to your computer and use it in GitHub Desktop.
shake me 摇一摇
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
- (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