Skip to content

Instantly share code, notes, and snippets.

@zedzhao
Created April 7, 2014 07:27
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 zedzhao/10016072 to your computer and use it in GitHub Desktop.
Save zedzhao/10016072 to your computer and use it in GitHub Desktop.
Determine if touch occurs in subview
- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
UIView *subView = [super hitTest:point withEvent:event];
if (UIEventTypeTouches == event.type) {
BOOL isOutsideTouch = (subView != self);
if(!isOutsideTouch){
for (UIView *s in self.subviews){
if (s == subView) {
isOutsideTouch = NO;
break;
}
}
}
if (isOutsideTouch) {
// self.outsideTouchBlock();
NSLog(@"outside touch");
}else{
// self.insideTouchBlock();
NSLog(@"inside touch");
}
}
return subView;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment