JorisT
JorisT

Reputation: 1552

UIToolbar - Allow interaction below toolbar

I have a custom UIToolbar in my UINavigationController, with a custom background image. The image is half transparent on the right. The problem that I'm having is that some views have buttons on the bottom right and the bottom part of those buttons cannot be tapped because the toolbar blocks it.

I cannot set userInteractionEnabled = NO on the UIToolBar, because the bar contains UIBarButtonItems which need to remain interactive.

Is there a way to make the bar ignore tap inputs (but not the UIBarButtonItems)?

Upvotes: 0

Views: 637

Answers (1)

jszumski
jszumski

Reputation: 7416

You can set userInteractionEnabled = YES on the toolbar, but override hitTest:point as described in How to get touches when parent view has userInteractionEnabled set to NO in iOS. This makes it ignore any touches on itself, but accept any touches on any subviews (UIBarButtonItems in your case):

- (id)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    id hitView = [super hitTest:point withEvent:event];

    if (hitView == self) {
        return nil;

    } else {
        return hitView;
    }
}

Note that this would require you to subclass UIToolbar.

Upvotes: 1

Related Questions