macoscocoansviewresponder-chain

How to keep a hidden view in responder chain?


I have a NSSplitViewController and in one of the items I have multiple buttons with keyboard shortcuts.

Once the user hides the item, the shortcuts don't fire. Is there any way to keep the buttons in the hidden view as part of the responder chain?


Solution

  • Sounds like the simple answer is no, according to Apple's docs. A simple workaround, however, might be to move the buttons out of the visible area by, say, shifting their bounds right by 10,000 or so. If they are in a scrollview/clipview that would expand to show the items in their new position, then this would not work so well, but if they aren't, it ought to work fine. If they are in a scrollview, then you might find a way to make them completely transparent, to achieve a similar effect.

    That said, perhaps it is worth considering whether you have the right design in the first place, since having buttons that are not visible respond to key events is a questionable design from a user-interface perspective (as reflected by the fact that Apple tries to prevent it). Maybe those keyboard events should really be getting handled by a view higher in the view hierarchy, or by the window, or some such entity?