Last active
August 16, 2017 08:52
-
-
Save dreampiggy/f7dd13865f46bf9e9d35f2013d86c9d7 to your computer and use it in GitHub Desktop.
iOS Hit Testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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