// 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) 點(diǎn)在矩形之內(nèi)
return CGRectContainsPoint(rect, point) ? self : nil;
}
1.實(shí)際上就是通過UIView的- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event(判斷點(diǎn)擊的點(diǎn)是否在本view之中)這個(gè)方法。重寫這個(gè)方法可以增大CGRect的范圍來是的點(diǎn)擊的點(diǎn)在設(shè)置的CGRect之中