MotionEnded 未被调用(无视图控制器)
我想我已经做了所有应该检测到的震动,但是 motionEnded:withEvent:
从未被调用。 (一个问题是我没有 UIViewController
- 我的应用程序基于“OpenGL ES App”模板。)
我添加了 application.applicationSupportsShakeToEdit = YES;
到我的 application:didFinishLaunchingWithOptions:
,以及
- (BOOL)canBecomeFirstResponder { return YES; }
EAGLView.m(确实被调用),以及 [self comeFirstResponder];
到 initWithCoder:
(并且也尝试过其他各种地方)。
但调试器从未命中
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
我是否错过了某些步骤?我必须有一个控制器吗?
(我在 iPad 模拟器中使用 iOS 3.2。)
I think I've done all I should to detect a shake, but motionEnded:withEvent:
never gets called. (One wrinkle is that I don't have a UIViewController
- my app is based on the "OpenGL ES App" template.)
I've added application.applicationSupportsShakeToEdit = YES;
to my application:didFinishLaunchingWithOptions:
, and
- (BOOL)canBecomeFirstResponder { return YES; }
to EAGLView.m (which does get called), and [self becomeFirstResponder];
to initWithCoder:
(and have tried various other places too).
But the debugger never hits
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
Am I missing some step? Do I have to have a controller?
(I'm using iOS 3.2 in the iPad simulator.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您必须将其添加到您的控制器中:
You must add this to your controller:
UIResponder
链处理摇动通知的方式令人讨厌。似乎UIWindow
总是收到通知,然后子响应者可能会或可能不会取决于链中它们上面的内容。我创建了一个 UIWindow 子类,并将其定义为我的窗口类,如下所示:然后,对于任何需要摇动通知的视图,我只需让它们将自己添加为 UIEventSubtypeMotionShakeEnded 的观察者 事件,他们每次都得到它。
The way the
UIResponder
chain works with the shake notification is obnoxious. Seems thatUIWindow
always gets the notification, and then sub-responders may or may not depending on whats above them in the chain. I created aUIWindow
subclass, and defined it as my window class with the following:Then, for any views that wanted the shake notifications, I simply had them add themselves as an observer to the
UIEventSubtypeMotionShakeEnded
event, and they got it every time.在您的视图进入视图层次结构之前,您无法成为第一响应者。
You can't become the first responder before your view is in the view hierarchy.
更新到最新版本的 SDK 神奇地解决了这个问题。 [耸肩]
Updating to the latest version of the SDK magically fixed the problem. [Shrug]