I have a UIViewController subclass that I am trying to have handle the shake event when its view is up.
Here are the relevant methods I've implemented:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self becomeFirstResponder];
}
- (void)viewDidDisappear:(BOOL)animated {
[self resignFirstResponder];
[super viewDidDisappear:animated];
}
- (BOOL)canBecomeFirstResponder {
return YES;
}
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if (motion == UIEventTypeMotion && event.type == UIEventSubtypeMotionShake) {
NSLog(@"%@ motionEnded", [NSDate date]);
}
if ([super respondsToSelector:@selector(motionEnded:withEvent:)]) {
[super motionEnded:motion withEvent:event];
}
}
You would expect that when I hit ^+Cmd+Z in the iPhone Simulator that it would just log once, but it is consistently logging twice for each event. Below is the result of three "shake" simulations:
2009-10-09 20:52:06.216 TestApp[39802:20b] 2009-10-09 20:52:06 -0400 motionEnded
2009-10-09 20:52:06.218 TestApp[39802:20b] 2009-10-09 20:52:06 -0400 motionEnded
2009-10-09 20:52:07.689 TestApp[39802:20b] 2009-10-09 20:52:07 -0400 motionEnded
2009-10-09 20:52:07.690 TestApp[39802:20b] 2009-10-09 20:52:07 -0400 motionEnded
2009-10-09 20:52:08.001 TestApp[39802:20b] 2009-10-09 20:52:08 -0400 motionEnded
2009-10-09 20:52:08.002 TestApp[39802:20b] 2009-10-09 20:52:08 -0400 motionEnded
Has anyone seen this and, if so, how did you fix it? I'm using iPhone SDK 3.1 and Xcode Version 3.1.4.