Skip to content

Instantly share code, notes, and snippets.

@zld
Created August 31, 2016 10:45
Show Gist options
  • Save zld/cea2eafe216ecf4ba6a6458f5147dbaf to your computer and use it in GitHub Desktop.
Save zld/cea2eafe216ecf4ba6a6458f5147dbaf to your computer and use it in GitHub Desktop.
// http://stackoverflow.com/a/17329683/2138564
// File - UITabBar+IKTouch.m
#import "UITabBar+IKTouch.h"
#import "UIView+IKTouch.h"
@implementation UITabBar (IKTouch)
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
return [self overlapHitTest:point withEvent:event];
}
@end
// File - UIView+IKTouch.m
#import "UIView+IKTouch.h"
@implementation UIView (IKTouch)
- (UIView *)overlapHitTest:(CGPoint)point withEvent:(UIEvent *)event {
// 1
if (!self.userInteractionEnabled || [self isHidden] || self.alpha == 0)
return nil;
// 2
UIView *hitView = self;
if (![self pointInside:point withEvent:event]) {
if (self.clipsToBounds) return nil;
else hitView = nil;
}
// 3
NSEnumerator *enumerator = [self.subviews reverseObjectEnumerator];
NSMutableArray *items = [[NSMutableArray alloc] init];
for (id element in enumerator) {
[items addObject:element];
}
for (UIView *subview in items ) {
CGPoint insideSubview = [self convertPoint:point toView:subview];
UIView *sview = [subview overlapHitTest:insideSubview withEvent:event];
if (sview) return sview;
}
// 4
return hitView;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment