Created
October 8, 2014 18:57
-
-
Save jonathan-beebe/0eb85564bce2b274a2e0 to your computer and use it in GitHub Desktop.
Helpful category for finding a subview during a gesture
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
#import <UIKit/UIKit.h> | |
typedef BOOL (^TestViewCallback)(UIView*); | |
@interface UIView (FindSubview) | |
- (UIView*) findSubviewWithTest:(TestViewCallback)callback; | |
- (BOOL) hitByGesture:(UIGestureRecognizer*)recognizer; | |
@end |
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
#import "UIView+FindSubview.h" | |
@implementation UIView (FindSubview) | |
- (UIView*) findSubviewWithTest:(TestViewCallback)callback | |
{ | |
UIView* view = nil; | |
for (UIView *subview in self.subviews) | |
{ | |
view = callback(subview) ? subview : [subview findSubviewWithTest:callback]; | |
if(view != nil) { | |
break; | |
} | |
} | |
return view; | |
} | |
- (BOOL) hitByGesture:(UIGestureRecognizer*)recognizer | |
{ | |
CGPoint point = [recognizer locationInView:self]; | |
return [self pointInside:point withEvent:nil]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment