How to run UITapGestureRecognizer in a child view that is partially cropped by the parent view?

Settings: I have a parent view A. It has a child view B. B is partially inside the borders of A, but partially outside (A has clips ToBounds = false). I bound UITapGestureRecognizer (UITGR) to B.

Compliant: UITGR fires normally when I click on part B located within A. UITGR does NOT start when I click on part B that is outside A.

Expected / Question: how do I make UITGR fire when I click on part B that goes beyond A?

+5
source share
2 answers

This quote will answer your question about why it behaves like this:

. window , . hit-testing hitTest: withEvent: ; pointInside: withEvent: , YES, , subview, . -. ()

UITapInSubviewsView hitTest:

(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    NSEnumerator *reverseE = [self.subviews reverseObjectEnumerator];
    UIView *iSubView;
    while ((iSubView = [reverseE nextObject])) {

        UIView *viewWasHit = [iSubView hitTest:[self convertPoint:point toView:iSubView] withEvent:event];
        if(viewWasHit)
           return viewWasHit;
     }
     return [super hitTest:point withEvent:event];
}

.

( S.O. , , ).

+6
0

All Articles