views:

625

answers:

3

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.

+1  A: 

Haven't seen this, but you might want to try it without invoking the super method. The default implementation of motionEnded (from UIResponder) is supposed to be a NOP so there's no need to call the parent method.

Also, have you tried this on the device itself? It could be a simulator issue.

Ramin
removing the super block still has the same effect. I haven't tested it on the actual device because I'm cheap and have been putting off paying for access to the iPhone developer program :).
Matt Baker
A: 

I have the same problem, also with the device.

What about a bug ? I wrote to apple. Wait and see…

MAGE
+3  A: 

Here what I have discovered, looks like a sim bug to me:

  1. Issue (double motionEnded notification) happens when target is OS 3.1 and 3.1.0 on sim
  2. Issue DOES not happen when target is 3.0 on sim

Issue NEVER happens on actual device regardless of the target.

so this must be a sim bug. When I have a chance I will submit as a bug to apple w/repro

leon
did you every get this fixed? Im having the same issue
Mark