tags:

views:

333

answers:

1

I am subclassing MainWindow with UIWindow and in that using hit test method:

-(UIView *)hitTestCGPoint)point withEventUIEvent *)event {

    UIView *hitView = [super hitTestoint withEvent:event];
    if (hitView == self)
        return [[self subviews] lastObject];
    else if([hitView isDescendantOfView:myView])
    {
        NSSet *touches = [event allTouches];

for (UITouch *touch in touches) {

if ([touches count] >= 2) { // prevent this NSLog(@"Count =2"); return [[self subviews] lastObject]; } } } return hitView; }

But I am getting touches as zero object. I debugged and checked event is always having 0 object. But responder is having details of the events . why is like that and how should I get the tap count ?

A: 

I think you should override -sendEvent: instead. The docs state the following about -sendEvent::

Dispatches events sent to the receiver by the UIApplication object to its views.

Costique
In -sendEvent, you can forward the events but can not be prevented.I have that already in my class.It just forwards the the events but if I want to filter it wont.
ashish
If you need to filter some events, call super conditionally. For example, if you want to suppress dispatching an event, just don't call super. Apple's implementation basically just does a hit test and sends -touchesBegan/Moved/Ended/Cancelled:withEvent: to a subview.That said, you have to be very careful filtering the events to avoid breaking the dispatching machinery. Can you provide more details on what you want to achieve?
Costique
I was trying to filter the events in - (void)sendEvent:(UIEvent *)event {//filter events for my custom View(WebView) //stop double tap on webview.Even thought I can figure out in hit test which view is getting tapped.}but Events are not getting filtered But it seems that (void)sendEvent:(UIEvent *)event already dispatches the events to webview.Then I thought I should try in hit test but as I told in hit test I am getting events as zero.
ashish