I have a UIView
that is partially stuck underneath a UINavigationBar
on a UIViewController
that's in full screen mode. The UINavigationBar
blocks the touches of this view for the portion that it's covering it. I'd like to be able to unblock these touches for said view and have them go through. I've subclassed UINavigationBar with the following:
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
UIView *view = [super hitTest:point withEvent:event];
if (view.tag == 399)
{
return view;
}
else
{
return nil;
}
}
...where I've tagged the view in question with the number 399. Is it possible to pass through the touches for this view without having a pointer to it (i.e. like how I've tagged it above)? Am a bit confused on how to make this work with the hittest method (or if it's even possible).
Subclass UINavigationBar and override
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
such that it returnsNO
for the rect where the view you want to receive touches is andYES
otherwise.For example:
UINavigationBar subclass .h:
UINavigationBar subclass .m:
In your fullscreen viewController where you have the view behind the navBar add these lines to
viewDidLoad
Please note: This will not send touches to the navigationBar, meaning if you add a view which is behind buttons on the navBar the buttons on the navBar will not receive touches.
Swift:
See the documentation for more info on
pointInside:withEvent:
Also if
pointInside:withEvent:
does not work how you want, it might be worth trying the code above inhitTest:withEvent:
instead.Here's a version which doesn't require setting the specific views you'd like to enable underneath. Instead, it lets any touch pass through except if that touch occurs within a
UIControl
or a view with aUIGestureRecognizer
.