问题描述
是否可以在app Delegate或其他任何地方处理关键UIWindow中的触摸事件?
Is it possible to handle touch events in the key UIWindow in the app Delegate or anywhere else?
请提供任何帮助。
推荐答案
在 UIWindow
中有一个方便的catch-all方法,名为 sendEvent :
,它可以看到事件处理管道开始附近的每个事件。如果你想做任何非标准的额外事件处理,这是一个放置它的好地方。这样的事情:
There is a handy catch-all method in UIWindow
called sendEvent:
which sees every event near the start of the event-handling pipeline. If you want to do any non-standard additional event handling, this is a good place to put it. Something like this:
- (void)sendEvent:(UIEvent *)event {
if ([self eventIsNoteworthy:event]) [self extraEventHandling:event];
[super sendEvent:event]; // Apple says you must always call this!
}
文档: |
还提到了如何覆盖 hitTest:withEvent:
以捕获一些事件,然后将它们绑定到视图层次结构中的目标叶子视图。如果需要,您还可以在 UIWindow
对象上覆盖该方法。
This blog post also mentions how to override hitTest:withEvent:
to catch some events before they're bound to the target leaf subview in the view hierarchy. You can also override that method on your UIWindow
object if you want.
这篇关于如何响应UIWindow中的触摸事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!