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?

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top