Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This seems to be a classic problem. In my case I wanted to intercept some events over a UIWebView which can't be subclassed, etc etc.</p> <p>I've found that the best way to do it is to intercept the events using the UIWindow:</p> <p>EventInterceptWindow.h</p> <pre><code>@protocol EventInterceptWindowDelegate - (BOOL)interceptEvent:(UIEvent *)event; // return YES if event handled @end @interface EventInterceptWindow : UIWindow { // It would appear that using the variable name 'delegate' in any UI Kit // subclass is a really bad idea because it can occlude the same name in a // superclass and silently break things like autorotation. id &lt;EventInterceptWindowDelegate&gt; eventInterceptDelegate; } @property(nonatomic, assign) id &lt;EventInterceptWindowDelegate&gt; eventInterceptDelegate; @end </code></pre> <p>EventInterceptWindow.m:</p> <pre><code>#import "EventInterceptWindow.h" @implementation EventInterceptWindow @synthesize eventInterceptDelegate; - (void)sendEvent:(UIEvent *)event { if ([eventInterceptDelegate interceptEvent:event] == NO) [super sendEvent:event]; } @end </code></pre> <p>Create that class, change the class of your UIWindow in your MainWindow.xib to EventInterceptWindow, then somewhere set the eventInterceptDelegate to a view controller that you want to intercept events. Example that intercepts a double-tap:</p> <pre><code>- (BOOL)interceptEvent:(UIEvent *)event { NSSet *touches = [event allTouches]; UITouch *oneTouch = [touches anyObject]; UIView *touchView = [oneTouch view]; // NSLog(@"tap count = %d", [oneTouch tapCount]); // check for taps on the web view which really end up being dispatched to // a scroll view if (touchView &amp;&amp; [touchView isDescendantOfView:webView] &amp;&amp; touches &amp;&amp; oneTouch.phase == UITouchPhaseBegan) { if ([oneTouch tapCount] == 2) { [self toggleScreenDecorations]; return YES; } } return NO; } </code></pre> <p>Related info here: <a href="http://iphoneincubator.com/blog/windows-views/360idev-iphone-developers-conference-presentation" rel="noreferrer">http://iphoneincubator.com/blog/windows-views/360idev-iphone-developers-conference-presentation</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload