Window Layout Best Practices

I'm not sure if I'm violating a rule here because I'm wanting opinions as opposed to a specific answer.


I have a MacOS application whose content does not change location or adjust shape. So, in IB, nearly every item I put in a view will be constrained Left and Top, and Width and Height. So if someone enlarges or shrinks the window size, everything inside stays put.


Recently, I'm noticing that if I add items to an existing view, if I move them around before setting constraints, this results in part of my original content being drastically moved around the view (like 50 pixels). In some cases my window size will enlarge by 200. It's obvious I'm either doing something wrong or I'm not understanding how IB/Storyboards/AutoLayout/Constraints work.


But my question is, given how I want to layout my window contents, is the way I do it the best way to achieve my desired result? Constraints top, left, width, height. Maybe using Stacks instead?

Accepted Reply

Recently, I'm noticing that if I add items to an existing view, if I move them around before setting constraints, this results in part of my original content being drastically moved around the view (like 50 pixels). In some cases my window size will enlarge by 200.


If the windows enlarges, that's probably because new objects create implicit constraints (look at so called struts and springs constraints, defined from the size button at the bottom of IB window.

You could also constrain the window size, to forbid this window resizing (give equal minimal and maximal sizes).


So if someone enlarges or shrinks the window size, everything inside stays put.

Why do you allow window to be resized. With your design, that gives ugly results in general.


Otherwise what you do seem correct (unless we were not told something).

Replies

Recently, I'm noticing that if I add items to an existing view, if I move them around before setting constraints, this results in part of my original content being drastically moved around the view (like 50 pixels). In some cases my window size will enlarge by 200.


If the windows enlarges, that's probably because new objects create implicit constraints (look at so called struts and springs constraints, defined from the size button at the bottom of IB window.

You could also constrain the window size, to forbid this window resizing (give equal minimal and maximal sizes).


So if someone enlarges or shrinks the window size, everything inside stays put.

Why do you allow window to be resized. With your design, that gives ugly results in general.


Otherwise what you do seem correct (unless we were not told something).

I give them the freedom to shrink the window to maybe allow a small amount of content to be visible in case they had other apps open. It's probably best if I forbid resizing.


On the constraints, I did copy/paste other objects to create my new ones. I'm wondering if the new item carries some constraints with it. That would make sense why a section of the view would move along with my object. I will test this out when I get home.

Yes, copy and paste may drag constraints.


It is better to create new objects.

My testing last night didn't reveal anything, but I do think that I need to pay closer attention to how all my objects are linked together (constraint-wise) when I try to insert new objects into that IB object tree. I probably just need to understand better how IB and auto-layout works...


The fact that you said my technique looked "normal" for what I'm trying to achieve is a good answer for me.

Thank you (again) Claude!