Skip to content

Instantly share code, notes, and snippets.

@canapio
Created August 26, 2016 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save canapio/61d3659369956c22a9b944a71f36fb6f to your computer and use it in GitHub Desktop.
Save canapio/61d3659369956c22a9b944a71f36fb6f to your computer and use it in GitHub Desktop.
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
if (!self.isUserInteractionEnabled || self.isHidden || self.alpha <= 0.01) {
return nil;
}
CGRect touchRect = CGRectInset(self.bounds, -10, -10);
if (CGRectContainsPoint(touchRect, point)) {
for (UIView *subview in [self.subviews reverseObjectEnumerator]) {
CGPoint convertedPoint = [subview convertPoint:point fromView:self];
UIView *hitTestView = [subview hitTest:convertedPoint withEvent:event];
if (hitTestView) {
return hitTestView;
}
}
return self;
}
return nil;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment