I'm detecting a shake that will start the animation, and when it ends, it stops animating. Sometimes it works, but sometimes it doesn't realize the shake has ended so it'll never call the motionEnded method. Has anyone else had this problem? Solutions?
-(BOOL)canBecomeFirstResponder {
return YES;
}
-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:NO];
[self becomeFirstResponder];
}
-(void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:NO];
}
-(void)viewDidDisappear:(BOOL)animated {
[self resignFirstResponder];
[super viewDidDisappear:NO];
}
-(void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
if (event.type == UIEventSubtypeMotionShake )
{
NSLog(@"1");
[img startAnimating];
}
}
-(void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
if (event.type == UIEventSubtypeMotionShake )
{
NSLog(@"3");
[img stopAnimating];
}
}
Apple seems to discuss the "inconsistency" you're experiencing here: http://developer.apple.com/library/ios/#documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/MotionEvents/MotionEvents.html
Under listing 4-2 it reads:
I would suggest adding a motionCancelled:withEvent callback to see if that's what's happening in those cases where you don't get a motionEnded call.