I have a static NSTextField
that overlays a large error message in my OS X app. I\'m trying to get it to allow the user to click controls beneath it.
In
I assume you are describing a scenario like the following image shows:
The inner red rectangle is the frame outline of the NSTextField
label, and you're saying that even though you've disabled the text field and set refuses first responder, your clicks do not go through to the NSButton
?
This design scenario describes a condition called "Overlapping sibling views". I would generally try to avoid this if at all possible. If you can't, you can get the desired behavior by making sure that the NSTextField
label is "behind" all of the other UI objects that you want to be able to interact with. You can do that by selecting the label and choosing Editor > Arrange > Send to Back. That will assure that the button is in front of the text field so that it can properly intercept mouse events.
The only way I have found to make an object transparent to the click is to subclass that object (in your case the NSTextField) and override the hitTest method returning nil. This way that NSTextField will not respond to the click so the NSView below will respond to the click.
- (NSView*)hitTest:(NSPoint)aPoint
{
return nil;
}