超出父视图范围的子视图响应事件

//重写该方法后可以让超出父视图范围的子视图响应事件

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {

        UIView *view = [super hitTest:point withEvent:event];

        if (view == nil) {

                for (UIView *subView in self.subviews) {

                        CGPoint tp = [subView convertPoint:point fromView:self];

                        if (CGRectContainsPoint(subView.bounds, tp)) {

                                  view = subView;

                         }

                 }

         }

        return view;

}

你可能感兴趣的:(超出父视图范围的子视图响应事件)