Search code examples
iosobjective-cuiviewuinavigationcontrolleruinavigationbar

How do I use hitTest:withEvent: to send touches from my nav bar to the underlying view under certain circumstances?


Long story short, if the alpha of my UINavigationBar is set to 0, I want all touches to go to the underlying view (which from the perspective of the view controller with the navigation bar would just be self.view). If it's 1.0, I want it to keep them.

I subclassed UINavigationBar, and I'm trying to override hitTest:withEvent:, but I'm really confused what I'm doing, and searching has been of little help.

How do I tell it, "if alpha is 0, send touch to self.view, otherwise keep on navigation bar"?


Solution

  • You will need to send a reference of your view into the navigation bar, set it as a property called behindView or something.

    if(self.alpha == 0.0f)
    {
        return behindView;
    }
    return [super hitTest:point withEvent:event];
    

    Another way would be to override pointInside:withEvent: like this:

    if(self.alpha == 0.0f)
    {
        return NO;
    }
    return [super pointInside:point withEvent:event];