UIButton超出superview的边界响应事件的方法

问题所在:UIButton是某UIView的子视图,但是UIButton超出了UIView的边界,正常情况下点击事件会失效。在该UIView下实现- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent*)event就能解决此问题。代码如下:

//其中detailBtn就是超出边界的按钮

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
         UIView *result = [super hitTest:point withEvent:event];
         CGPoint buttonPoint = [detailBtn convertPoint:point fromView:self];
         if ([detailBtn pointInside:buttonPoint withEvent:event]) {
                   return detailBtn;
          }
          return result;
}

你可能感兴趣的:(UIButton超出superview的边界响应事件的方法)