HypnosisView does not respond to motion events


Note: This is “extra credit” work in chapter seven. I was able to get motion events in chapter six.

I just added the HypnosisView in chapter seven when I noticed it no longer responds to motion events to change the color. No problem, I’ll just set the view to become the first responder. Unfortunately that’s not working.

I added the following setup code to the code from page 148:

[code]- (void)loadView
// Create a view
CGRect frame = [[UIScreen mainScreen] bounds];
HypnosisView *v = [[HypnosisView alloc] initWithFrame:frame];

// Set it as *the* view of the view controller
[self setView:v];

BOOL success = [v becomeFirstResponder];
if (success)
    NSLog(@"HypnosisView became the first responder");
    NSLog(@"HypnosisView could not become the first responder");


In the debugger I see the call to canBecomeFirstResponder in HypnosisView.m which returns YES, but something in the assembly changes the answer to NO. I thought I might need to set the ViewController to become the first responder, but the documentation (and further experiments) suggest that’s not the case. Why can’t the view become the first responder? Is there a good way to debug this?



Once I moved the HypnosisViewController into an UITabBarController, HypnosisView was able to become first responder and handle motion events. It appears that setting HypnosisViewController as the RootViewController was causing a problem. Not sure why.