Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7904513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:06:24+00:00 2026-06-03T10:06:24+00:00

like this question , i have an NSView which is the contentView for an

  • 0

like this question, i have an NSView which is the contentView for an NSWindow and it contains several subviews stacked vertically one above the other. some of them are fixed size and some of them can be expanded or collapsed with a disclosure button.

i want to implement a kind of “accordion” effect where expanding or collapsing one of the subviews makes everything else adjust and resizes the superview and the window accordingly.

it really seems like one ought to be able to accomplish this by setting up the right set of constraints with auto layout and i have it now doing the initial layout fine. but i can’t figure out how to set up constraints so that the superview automatically re-sizes to hug the sub-views.

the OP in the question linked above never got an answer and provided his own solution like the one that i was starting to implement independently, but i thought i would throw it out there once again in case there are any auto layout gurus that know a trick. it seems like there should be a way to get the superview to hug the subviews by leveraging auto layout without having to manually calculate the sizes of the subviews and manually reset the size of the superview.

anyone know how?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T10:06:25+00:00Added an answer on June 3, 2026 at 10:06 am

    Autolayout is cool and comprehensive. And arcane.

    I tried hard but could not come up with a set of constraints that would do what I wanted to do. It still seems to me that if you stack some NSView’s vertically inside a superview and set up the constraints such that the top subview is pinned to the top of the superview and going down the stack of subviews you pin each one’s top to the bottom edge of the one above and then finally you pin the bottom edge of the last subview to the bottom edge of the superview and you then programmatically resize one or more of the subviews it should be able to pull up or push down on the bottom of the superview to keep it hugging its subviews.

    Everything works as expected except for the last piece. When you try to pin the bottom subview to the bottom of the superview, auto layout can’t satisfy all the constraints. It seems like resizing the superview to satisfy the constraints is not in the algorithm. Either that or I am missing some other constraint that needs setting.

    And while I am on the subject, looking at the debugger, it appears that there are un-settable constrains at play between a window’s contentView and the window frame. I kind of wonder if being able to mess with those constraints would let the original scheme work.

    Anyway, I did come up with a solution that uses autolayout and it is pretty close to what I was hoping autolayout would do because all that was necessary was subclassing NSView and putting a few lines of code into the intrinsicSize method and then using that subclass for the superview.

    i created an xcode project that has my collapsible views base classes and a working demo of the whole thing on github.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My question like this: I have a JTable, I put a JProgressBar in one
Kind of like this question I have many text snippets that I use many,
Absolute beginner question: I have a template file index.html that looks like this: ...
I have a route defined like this: GET /question/:q_id controllers.Questions.viewQuestion(q_id: Long) Then in my
I have a schema like this <h1> 5/2009 <br/> Question: This is the question
I have a question. I have plotted a graph using Matplotlib like this: from
Sounds like a weird question, but say I have something like this: $.post( /myajax.php,
This is a really basic question but... I have some code like this var
Newbie question. I have Django models that look like this: class Video(models.Model): uploaded_by =
may be too simple groovy question but....please help i have a list like this:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.