AleMal
AleMal

Reputation: 2077

iPhone shake event not work

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?

Upvotes: 0

Views: 227

Answers (1)

Nikola Kirev
Nikola Kirev

Reputation: 3152

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.

Upvotes: 1

Related Questions