tags:

views:

52

answers:

2

Hi there,

I'm using this code to do shake detection, and for the most part it works fine:

    - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
 if (event.type == UIEventSubtypeMotionShake) {
  if ( event.subtype == UIEventSubtypeMotionShake )
  {
   NSLog (@"Shake Called");
  }  
 }

I believe for this to work, I also needed to use these, which I have:

    - (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self becomeFirstResponder];
}

- (void)viewDidDisappear:(BOOL)animated {
    [self resignFirstResponder];
    [super viewDidDisappear:animated];
}

This all works great, and motionEnded is called every time I shake, until I click through a link in a webView on my program. I can scroll up and down in the view and shake still works, but as soon as the view loads a new page, motionEnded stops being called when I shake. This occurs both in the simulator and on a real device (iPhone 3G, iOS4). From my limited understanding, I believe it has something to do with first responders, but I could be wrong there!

Any ideas interweb people?

Thanks,

Joe

A: 

I have managed to answer my own question. For the reference of others who may have similar problems, the issue is that the viewController stops being the first responder once you click a link in a webView (or edit a text box, or some similar action). To fix the issue in my case, the answer was to make the viewController the first responder again after the new page loads:

    - (void)webViewDidFinishLoad:(UIWebView *)nameOfWebView {
    [self becomeFirstResponder];
}
Colonel Panic
A: 

I have the same problem, but becoming first reponder when web view finishes loading doesn't solve it for me. I know webViewDidFinishLoad gets called when a new page has been loaded, and I also know motionEnded gets called when I focus the web view by tapping it and then shaking or simulating shake.

Minthos
Never mind, I found the answer here: http://stackoverflow.com/questions/1547805/shake-detection-iphone-3-0-not-workingI needed to have this function defined:-(BOOL)canBecomeFirstResponder{ return YES;}
Minthos