Question

How can you get an NSButton to detach from an NSStackView when the stack view resizes?

NSControl subclasses that use NSCell drawing seem to have a different mind than other NSView subclasses on visibility with compression resistance in Auto Layout. NSStackView doesn't seem to make a difference here either.

If I set the Visibility Priority for a control higher than 1, it will not drop. If I set it to 0, well, of course it will only drop and never appear.

How is this supposed to work?
What does it take to get a button or other control to drop when the stack view is resized smaller?
Maybe it's the dearth of docs and examples of NSStackView...

Was it helpful?

Solution

Before I saw any views detach, I had to do two things:

  1. Call -[NSStackView setClippingResistancePriority:forOrientation:]. If the size of the stack view is tied to the size of the window, the priority needs to be less than NSLayoutPriorityWindowSizeStayPut (500) or the stack view doesn't allow the window to get smaller than its content.

  2. Each time I added a view to the stack view that I wanted to detach, call -[NSStackView setVisibilityPriority:forView:] for that view.

OTHER TIPS

Try setting the priority to NSStackViewVisibilityPriorityDetachOnlyIfNecessary?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top