MotionEnded 被多次调用
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是我发现的,对我来说看起来像一个 sim bug:
问题永远不会发生在实际设备上,无论如何目标。
所以这一定是一个SIM错误。
当我有机会时,我会将错误提交给苹果并进行重现
Here what I have discovered, looks like a sim bug to me:
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
还没有看到这个,但您可能想尝试一下而不调用 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.