UIView超出父view的部分视图的子视图响应事件

2021-08-18  本文已影响0人  野码道人
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    UIView *view = [super hitTest:point withEvent:event];
    CGPoint clickPoint = CGPointZero;
    if (view == nil) {
        for (UIView *subView in self.subviews) {
            clickPoint = [subView convertPoint:point fromView:self];
            if (CGRectContainsPoint(subView.bounds, clickPoint)) {
                view = subView;
                break;
            }
        }
    }
    CGPoint finalClickPoint = clickPoint;
    if ([view isMemberOfClass:NSClassFromString(@"超出父view的视图类名")]) {
        for (UIView *subView in view.subviews) {
            finalClickPoint = [subView convertPoint:clickPoint fromView:view];
            if (CGRectContainsPoint(subView.bounds, finalClickPoint)) {
                view = subView;
                break;
            }
        }
    }
    return view;
}
上一篇下一篇

猜你喜欢

热点阅读