Passing through touches to UIViews underneath

前端 未结 5 1374
庸人自扰
庸人自扰 2020-12-01 03:17

I have a UIView with 4 buttons on it and another UIView on top of the buttons view. The top most view contains a UIImageView with a <

5条回答
  •  清歌不尽
    2020-12-01 04:11

    The UIGestureRecognizer is a red herring I think. In the end to solve this I overrode the pointInside:withEvent: method of my UIView:

    - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
        BOOL pointInside = NO;
    
        if (CGRectContainsPoint(imageView.frame, point) || expanded) pointInside = YES;
    
        return pointInside;
    }
    

    This causes the view to trap all touches if you touch either the imageView or if its expanded flag is set. If it is not expanded then only trap the touches if they are on the imageView.

    By returning NO, the top level VC's View queries the rest of its view hierarchy looking for a hit.

提交回复
热议问题