sehugg
sehugg

Reputation: 3605

becomeFirstResponder seems to work only 1st time for shake gesture

I'm making my app shake-gesture-compatible by doing this in my UIViewController:

- (void)viewWillAppear:(BOOL)animated
{
    [self.view becomeFirstResponder];
    [super viewWillAppear:animated];
}

The problem is that when I flip to another view (I'm using the "Utility App" template which has a flipside view and a root view controller to manage them both) the shake gesture ceases to work when I come back.

I see that the viewWillAppear method is called, it just doesn't seem that the view regains first responder status the second time around.

Upvotes: 0

Views: 1302

Answers (2)

mobibob
mobibob

Reputation: 8794

Yup, that confirms it for me ... I was trying to set the controllers as firstResponder from the application delegate. Meanwhile, I found it very helpful for debugging to sprinkle this log statement in strategic methods.

NSLog(@"%s: I %s first responder! (%@)", __FUNCTION__, [self isFirstResponder] ? "am" : "am not", self);

Also, to allow me to trigger it at arbitrary times, I enabled the "orientation" method and put it in there.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
NSLog(@"%s: I %s first responder! (%@)", __FUNCTION__, [self isFirstResponder] ? "am" : "am not", self);
return YES;
}

Upvotes: 1

sehugg
sehugg

Reputation: 3605

Who knew .. you have to put the call to becomeFirstResponder in viewDidAppear instead of viewWillAppear.

Upvotes: 2

Related Questions