Created
April 18, 2014 02:20
-
-
Save elizaaverywilson/11021595 to your computer and use it in GitHub Desktop.
FInd a view that looks like something you can touch given point
This file contains hidden or 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*)responderForPoint:(CGPoint)point { | |
| UIView *rootView = self; | |
| while (1) { | |
| if (!rootView.superview) { | |
| rootView = rootView.superview; | |
| } | |
| } | |
| UIView *gameViewRootView = [rootView viewWithTag: NNGameViewRootViewTag]; | |
| UIView *responder = [self responderOf: gameViewRootView forPoint:point]; | |
| return responder; | |
| } | |
| - (UIView*)responderOf:(UIView*)view forPoint:(CGPoint)point { | |
| if (view) { | |
| if (!view.subviews) { | |
| if (view.userInteractionEnabled) { | |
| if (CGRectContainsPoint(view.frame, point)) { | |
| for (Class allowedResponderClass in (Class)[self allowedResponderClasses]) { | |
| if ([view isKindOfClass: allowedResponderClass]) { | |
| return view; | |
| } | |
| } | |
| } | |
| } | |
| } else { | |
| for (NSUInteger i = 0; i < view.subviews.count; i++) { | |
| UIView *subview = (UIView*)view.subviews[i]; | |
| UIView *responder = [self responderOf: subview forPoint:point]; | |
| if (responder) { | |
| return responder; | |
| } | |
| } | |
| } | |
| } | |
| return nil; | |
| } | |
| - (NSArray*)allowedResponderClasses { | |
| return [NSArray arrayWithObjects: | |
| [UIButton class] | |
| , nil]; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment