MotionEnded 被多次调用

发布于 2024-08-08 04:48:26 字数 1364 浏览 9 评论 0原文

我有一个 UIViewController 子类,我试图在其视图启动时处理摇动事件。

以下是我已实现的相关方法:

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self becomeFirstResponder];
}

- (void)viewDidDisappear:(BOOL)animated {
    [self resignFirstResponder];
    [super viewDidDisappear:animated];
}

- (BOOL)canBecomeFirstResponder {
    return YES;
}

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
    if (motion == UIEventTypeMotion && event.type == UIEventSubtypeMotionShake) {
        NSLog(@"%@ motionEnded", [NSDate date]);
    }

    if ([super respondsToSelector:@selector(motionEnded:withEvent:)]) {
        [super motionEnded:motion withEvent:event];
    } 
}

您可能会期望当我在 iPhone 模拟器中按下 ^+Cmd+Z 时,它只会记录一次,但它始终为每个事件记录两次。下面是三个“摇动”模拟的结果:

2009-10-09 20:52:06.216 TestApp[39802:20b] 2009-10-09 20:52:06 -0400 MotionEnded
2009-10-09 20:52:06.218 TestApp[39802:20b] 2009-10-09 20:52:06 -0400 运动结束
2009-10-09 20:52:07.689 TestApp[39802:20b] 2009-10-09 20:52:07 -0400 运动结束
2009-10-09 20:52:07.690 TestApp[39802:20b] 2009-10-09 20:52:07 -0400 运动结束
2009-10-09 20:52:08.001 TestApp[39802:20b] 2009-10-09 20:52:08 -0400 运动结束
2009-10-09 20:52:08.002 TestApp[39802:20b] 2009-10-09 20:52:08 -0400motionEnded

有没有人看到过这个,如果有,你是如何解决的?我正在使用 iPhone SDK 3.1 和 Xcode 版本 3.1.4。

I have a UIViewController subclass that I am trying to have handle the shake event when its view is up.

Here are the relevant methods I've implemented:

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self becomeFirstResponder];
}

- (void)viewDidDisappear:(BOOL)animated {
    [self resignFirstResponder];
    [super viewDidDisappear:animated];
}

- (BOOL)canBecomeFirstResponder {
    return YES;
}

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
    if (motion == UIEventTypeMotion && event.type == UIEventSubtypeMotionShake) {
        NSLog(@"%@ motionEnded", [NSDate date]);
    }

    if ([super respondsToSelector:@selector(motionEnded:withEvent:)]) {
        [super motionEnded:motion withEvent:event];
    } 
}

You would expect that when I hit ^+Cmd+Z in the iPhone Simulator that it would just log once, but it is consistently logging twice for each event. Below is the result of three "shake" simulations:

2009-10-09 20:52:06.216 TestApp[39802:20b] 2009-10-09 20:52:06 -0400 motionEnded
2009-10-09 20:52:06.218 TestApp[39802:20b] 2009-10-09 20:52:06 -0400 motionEnded
2009-10-09 20:52:07.689 TestApp[39802:20b] 2009-10-09 20:52:07 -0400 motionEnded
2009-10-09 20:52:07.690 TestApp[39802:20b] 2009-10-09 20:52:07 -0400 motionEnded
2009-10-09 20:52:08.001 TestApp[39802:20b] 2009-10-09 20:52:08 -0400 motionEnded
2009-10-09 20:52:08.002 TestApp[39802:20b] 2009-10-09 20:52:08 -0400 motionEnded

Has anyone seen this and, if so, how did you fix it? I'm using iPhone SDK 3.1 and Xcode Version 3.1.4.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

红尘作伴 2024-08-15 04:48:26

这是我发现的,对我来说看起来像一个 sim bug:

  1. 当目标是 sim 上的 OS 3.1 和 3.1.0 时,会发生问题(双motionEnded 通知) 当 sim 上的
  2. 目标是 3.0 时,不会发生问题

问题永远不会发生在实际设备上,无论如何目标。

所以这一定是一个SIM错误。
当我有机会时,我会将错误提交给苹果并进行重现

Here what I have discovered, looks like a sim bug to me:

  1. Issue (double motionEnded notification) happens when target is OS 3.1 and 3.1.0 on sim
  2. Issue DOES not happen when target is 3.0 on sim

Issue NEVER happens on actual device regardless of the target.

so this must be a sim bug.
When I have a chance I will submit as a bug to apple w/repro

意中人 2024-08-15 04:48:26

还没有看到这个,但您可能想尝试一下而不调用 super 方法。 motionEnded(来自 UIResponder)的默认实现应该是 NOP,因此无需调用父方法。

另外,您是否在设备本身上尝试过此操作?可能是模拟器的问题。

Haven't seen this, but you might want to try it without invoking the super method. The default implementation of motionEnded (from UIResponder) is supposed to be a NOP so there's no need to call the parent method.

Also, have you tried this on the device itself? It could be a simulator issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文