【问题标题】:iPhone Shake event not properly workingiPhone Shake 事件无法正常工作
【发布时间】:2009-12-31 05:41:38
【问题描述】:

我的 viewController 里面有这个:

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

    if (event.type == UIEventSubtypeMotionShake) {

        NSLog(@"I have shaked");

    }
}

为什么这不起作用? 编辑:


我确实有这个:

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

【问题讨论】:

    标签: iphone shake motion-detection


    【解决方案1】:

    如果 UIViewController 在应用程序的一开始就加载,我在 OS 3.0 中看到了一个奇怪的故障,除非您稍微延迟适当的消息,否则它不会成为第一响应者。尝试放置

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

    在 -loadView 或首次设置控制器时调用的其他内容中。

    可能有更优雅的方法来解决这个问题,但这种方法对我有用。

    【讨论】:

      【解决方案2】:

      viewController 必须是摇动过程中的第一响应者才能接收此事件。

      这可能是它不起作用的原因之一。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多