Skip to content

Instantly share code, notes, and snippets.

@dreampiggy
Last active August 16, 2017 08:52
Show Gist options
  • Save dreampiggy/f7dd13865f46bf9e9d35f2013d86c9d7 to your computer and use it in GitHub Desktop.
Save dreampiggy/f7dd13865f46bf9e9d35f2013d86c9d7 to your computer and use it in GitHub Desktop.
iOS Hit Testing
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
if (!self.isUserInteractionEnabled || self.isHidden || self.alpha <= 0.01) {
return nil;
}
if ([self pointInside:point withEvent:event]) {
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