I am trying to implement the “tutorial” trick on this page, but I think something is missing. I copied his accelerometer function to the myAppViewController.m file and put several nslog there to see if it even gets into the function when I use the shake function of the simulators. Nothing is displayed in the debug console.
http://mithin.in/2009/07/28/detecting-a-shake-using-iphone-sdk
Can someone explain what I can lose? Or point me to a textbook?
I found this that looks promising, but I don’t know how to “put it in a UIView”, How to determine when someone shakes the iPhone?
EDIT - now here is my working code due to the accepted answer.
Here is my code to detect the shake gesture in the 3.0 iphone sdk.
-(BOOL)canBecomeFirstResponder { return YES; } -(void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [self becomeFirstResponder]; } - (void)viewWillDisappear:(BOOL)animated { [self resignFirstResponder]; [super viewWillDisappear:animated]; } - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event { NSLog(@"{motion ended event "); if (motion == UIEventSubtypeMotionShake) { NSLog(@"{shaken state "); } else { NSLog(@"{not shaken state "); } }
Neo42
source share