Skip to content

Instantly share code, notes, and snippets.

@jonathan-beebe
Created October 8, 2014 18:57
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 jonathan-beebe/0eb85564bce2b274a2e0 to your computer and use it in GitHub Desktop.
Save jonathan-beebe/0eb85564bce2b274a2e0 to your computer and use it in GitHub Desktop.
Helpful category for finding a subview during a gesture
#import <UIKit/UIKit.h>
typedef BOOL (^TestViewCallback)(UIView*);
@interface UIView (FindSubview)
- (UIView*) findSubviewWithTest:(TestViewCallback)callback;
- (BOOL) hitByGesture:(UIGestureRecognizer*)recognizer;
@end
#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