Skip to content

Instantly share code, notes, and snippets.

@leilee
Created July 5, 2018 09:49
Show Gist options
  • Save leilee/780d8a18891478cc864153a868148c6b to your computer and use it in GitHub Desktop.
Save leilee/780d8a18891478cc864153a868148c6b to your computer and use it in GitHub Desktop.
//override this in a UIView Custom Class
// check if any sub element inside view is outside bounds of the view
// if yes, expand the hitable area of view with its sub element
// http://stackoverflow.com/questions/11770743/capturing-touches-on-a-subview-outside-the-frame-of-its-superview-using-hittest
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
if (!self.clipsToBounds && !self.hidden && self.alpha > 0) {
for (UIView *subview in self.subviews.reverseObjectEnumerator) {
CGPoint subPoint = [subview convertPoint:point fromView:self];
UIView *result = [subview hitTest:subPoint withEvent:event];
if (result != nil) {
return result;
}
}
}
return nil;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment