MotionEnded is called multiple times
I have a UIViewController subclass that I am trying to handle the shake event when I view it.
Here are the relevant methods that I have 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 remove ^ + Cmd + Z in iPhone Simulator it will just log once, but it logs sequentially 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 am using iPhone SDK 3.1 and Xcode version 3.1.4.
source to share
Here's what I found looks like a sim error to me:
- Issue (double motionEnded notification) happens when target is OS 3.1 and 3.1.0 on sim
- Problem does NOT happen when target is 3.0 on SIM
The problem NEVER happens on the device itself, no matter the purpose.
so it must be a sim bug. When I have a chance, I will post as a bug for apple w / repro
source to share