I have the following structure of the views
UIView(1)
|--> UIScrollView
|-----------> UIView(2)
|------> UIButton
hitTest in UIView(1) has been overridden with the following:
- (UIView *)hitTest:(CGPoint) point withEvent:(UIEvent *)event
{
/* this view should have only view only: the scroll view */
UIView * vv = [[self subviews] objectAtIndex:0];
if ([vv pointInside:point withEvent:event])
{
UIView *rv = [vv hitTest:point withEvent:event];
return rv;
}
if ([self pointInside:point withEvent:event])
{
return vv;
}
return nil;
}
This is required in order to catch UIScrollView dragging outside of the scroll view itself.
The issue is that when the UIButton is clicked, the event attached to it does not fire. The view returned from the hitTest is UIView(2).
How can I make the UIButton to respond to clicking event?
Edit After suggestion of Mundi, I exchanged hitTest with the following and it works. Of course, I forgot to call [super hitTest:].
- (UIView *)hitTest:(CGPoint) point withEvent:(UIEvent *)event
{
/* this view should have only view only: the scroll view */
UIView * scrv = [self findScrollView];
UIView *superView = [super hitTest:point withEvent:event];
if (superView == self)
{
return scrv;
}
return superView;
}
How about calling [super hitTest:point withEvent:event]
at the appropriate point?