// UIView的方法
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
CGRect rect = [self enlargedRect];
if (CGRectEqualToRect(rect, self.bounds)) {
return [super hitTest:point withEvent:event];
}
// CGRectContainsPoint(rect, point) 点在矩形之内
return CGRectContainsPoint(rect, point) ? self : nil;
}
1.实际上就是通过UIView的- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event(判断点击的点是否在本view之中)这个方法。重写这个方法可以增大CGRect的范围来是的点击的点在设置的CGRect之中