iPhone Shake事件无法正常运行 [英] iPhone Shake event not properly working

查看:160
本文介绍了iPhone Shake事件无法正常运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的viewController中有这个

I have this inside my viewController:

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {

    if (event.type == UIEventSubtypeMotionShake) {

        NSLog(@"I have shaked");

    }
}

为什么这不起作用?

Why is this not working?

事实上,我确实有这个:

I do infact have this:

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

推荐答案

如果在应用程序的开头加载了UIViewController,我在OS 3.0中已经看到了一个奇怪的毛病,除非您将它变成第一响应者,否则它不会成为第一个响应者.延迟了适当的消息.尝试放置

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];

在-loadView内,或者在首次设置控制器时调用的其他内容.

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.

这篇关于iPhone Shake事件无法正常运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆