There seems to be an answer, but when I try the method provided, it just doesn't work!
@interface MyView : UIView
@end
@implementation MyView
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
UIView *hitView = [super hitTest:point withEvent:event];
NSLog(@"hitView:%@", hitView);
if (hitView == self) {
return nil;
}
return hitView;
}
- (void)testUserInteraction
{
UIViewController *vc = [[UIViewController alloc] init];
self.window.rootViewController = vc;
MyView *myView = [[MyView alloc] initWithFrame:CGRectMake(0, 0, 320, 568)];
myView.userInteractionEnabled = NO;
[vc.view addSubview:myView];
UIView *subView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 50, 50)];
subView.backgroundColor = [UIColor orangeColor];
[myView addSubview:subView];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped)];
[subView addGestureRecognizer:tap];
}
When myView.userInteractionEnabled = YES;
everything works fine. but when myView.userInteractionEnabled = NO;
wherever I tapped the screen, it just output hitView:(null)
So is this method no longer working, or did I miss something?