开发者

iPhone Shake event not properly working

开发者 https://www.devze.com 2022-12-14 23:53 出处:网络
I have this inside my viewController: - (void)motionEnded:(UIEventSubtyp开发者_Go百科e)motion withEvent:(UIEvent *)event {

I have this inside my viewController:

- (void)motionEnded:(UIEventSubtyp开发者_Go百科e)motion withEvent:(UIEvent *)event {

    if (event.type == UIEventSubtypeMotionShake) {

        NSLog(@"I have shaked");

    }
}

Why is this not working? Edit:


I do infact have this:

- (void) viewWillAppear:(BOOL)animated
{
    [shakeView becomeFirstResponder];
    [super viewWillAppear:animated];
}
- (void) viewWillDisappear:(BOOL)animated
{
    [shakeView resignFirstResponder];
    [super viewWillDisappear:animated];
}


If the UIViewController is loaded at the very start of the application, I've seen an odd glitch in OS 3.0 where it would not become the first responder unless you delayed the appropriate message a bit. Try placing

[self performSelector:@selector(becomeFirstResponder) withObject:nil afterDelay:0.3];

within -loadView or something else that is called when the controller is first set up.

There may be a more elegant way to work around this, but this approach has worked for me.


The viewController must be the first responder during the shake to receive this event.

This could be one reason it's not working.

0

精彩评论

暂无评论...
验证码 换一张
取 消