iOS 子视图超出父视图范围点击事件处理!

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
 
 UIView *view = [super hitTest:point withEvent:event];

  NSLog(@"1-----%f------%f",point.x,point.y);
  // 将point的x,y从以self为坐标系转换到以self.fb为坐标系进行参考
  CGPoint buttonPoint = [self.fb convertPoint:point fromView:self];
  NSLog(@"2-----%f------%f",buttonPoint.x,buttonPoint.y);
  if ([self.fb pointInside:buttonPoint withEvent:event]) {
    return self.fb;
  }
  return view;
}
//两者一样

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    UIView *view = [super hitTest:point withEvent:event];
    if (view == nil) {
        CGPoint tempoint = [self.senderBtn convertPoint:point fromView:self];
        if (CGRectContainsPoint(self.senderBtn.bounds, tempoint))
        {
            view = self.senderBtn;
        }
    }
    return view;
}

原文地址:https://www.cnblogs.com/yujidewu/p/5684029.html