When using the hitTest: withEvent method, decide if tap was involved

I am trying to override hitTest: withEvent in a custom view. This is a container view with many areas.

This "supervisor" is a gesture recognizer. In addition to this view, there are many subtitles (which, in turn, have more and more subviews), I decided to overcome hitTesh: withEvent to decide which view should receive events - and in which cases the supervisor should receive an event to trigger a gesture .

The problem I am facing is that hitTest will return a supervisor in cases where the selection gesture is initialized in a preview. In this case, I would like to "retroactively" ignore the action of the crane - and again "invoke" hitTest: withEvent in supervision. the supervisor may then decide to transmit the “true” responder to this event.

How to do it:

Example:

// In the container view

-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{

// the default view that would have been returned
  UIView *v = [super hitTest:point withEvent:event];

  // if nil than touch wasn't in this view so disregard
  if (v == nil)
  {
    return nil;
  }

  // if the touch was on a control than I don't want to take care of it
  if ([v isKindOfClass:[UIControl Class]])
  {
    return v;
  }

  // now here is where I need to fix

  // I am only interested in a touch event that would initiated a pan gesture
  // if the event was a tap for intance - than return [super hitTest:point withEvent:event]
  // for instance if a uitableview cell was tapped - I don't want to mask the event
  if (event wouldn't initiate a pan)
  {
    return v;
  }
  return self;
}
+3
source share

All Articles