NSTextField click-through?

后端 未结 2 879
半阙折子戏
半阙折子戏 2021-01-18 01:44

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

相关标签:
2条回答
  • 2021-01-18 01:45

    I assume you are describing a scenario like the following image shows:

    enter image description here

    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.

    0 讨论(0)
  • 2021-01-18 02:06

    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;
    }
    
    0 讨论(0)
提交回复
热议问题