Question

I have this inside my viewcontroller.m

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
    if (event.type == UIEventSubtypeMotionShake) {

    NSLog(@"shake shake shake");

    }
}

- (void)viewDidLoad
{
    [self performSelector:@selector(becomeFirstResponder) withObject:nil afterDelay:0.3];
}

But when I shake my phone nothing happens. Why?

Was it helpful?

Solution

I had the same problem and I'm not sure what is the reason for it. However, I have a solution.. When I call [self becomeFirstResponder] in the viewDidAppear method, the shake detection works.

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

I hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top