How to pass the touch event to superview when userInteractionEnabled = YES?

后端 未结 6 1096
青春惊慌失措
青春惊慌失措 2020-12-17 14:24

I have the following setup.

+- XXXCustomControl : UIControl -------+
| A                                    |
|   +- ContentView -------------------+|
|   |         


        
6条回答
  •  时光说笑
    2020-12-17 14:40

    Use this in super view, without changing subviews code (since subviews may be introduced from other frameworks or pods):

    - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
    {
        UIView *view = [super hitTest:point withEvent:event];
        if ([view isDescendantOfView:self])
        {
            NSLog(@"touched inside");
        }
        return view;
    }
    

提交回复
热议问题