0

OK, this might seem very simple but I've been struggling for too long, so I decided to ask for some help.

Basical, I've got a container NSView.

The contents are (from left to right):

  • an NSSegmentedControl
  • an NSTextField
  • an NSSegmentedControl

And they are all aligned horizontally (= they're in the same "line").

What I'm trying to do is:

  • Fixed width for the first element, and fixed on the left
  • resizeable textfield
  • Fixed width for the last element, and fixed on the right

I guess it's pretty self-explanatory.


And here are my autoresizing settings for the 3 views:

View 1

enter image description here

View 2

View 2

View 3

enter image description here


And here's the issue: the whole resizing works fine. Until the textfield is resized at such a point where it is collapsed. When the superview/container is resized at a normal size again, the whole design is messed up (with the textfield overflowing the container and lots of such weird issue).

What's going on? Any suggestions?


Note: I got it to work with Auto Layout (merely setting "Auto Layout" and "Add(ing) missing constraints"), but I most definitely want to avoid it since the performance impact is huge -- the overall design is rather complicated, with lots of nesting, so let's stick to the old-fashioned way. :-)

Dr.Kameleon
  • 22,532
  • 20
  • 115
  • 223
  • It is likely without auto-layout you will have to do the frame updates manually (which is still par for the course in a lot of applications) – Ryan Dignard Dec 13 '14 at 08:47
  • @RyanDignard Sorry if this sounds ignorant (it is - my experience with Auto Layout is close to zero): is it possible that I enable Auto Layout just for this particular view (and its contents) and leave the rest as it is? (Note: all of the masks are set through Interface Builder) – Dr.Kameleon Dec 13 '14 at 08:48
  • You could build your view as a series of independent nibs with some set to have auto-layout and some without and paste the whole thing together in viewDidLoad – Ryan Dignard Dec 13 '14 at 08:51
  • Auto layout is enabled at the granularity of a window. If any view in the window uses auto layout, then the whole window does. That said, you don't have to enable auto layout for a given view. If you don't set `translatesAutoresizingMaskIntoConstraints` (and IB doesn't set it for you), then that view's autoresizing mask is translated into constraints that work the same way. That can avoid some work on your part, but doesn't make anything more efficient at runtime. – Ken Thomases Dec 13 '14 at 08:54

1 Answers1

2

The old springs-and-struts model using autoresizing masks is based on proportional distribution of the change in size based on the current sizes of the subviews being resized. Once any subview gets to zero size, it goes haywire. Either there's division by zero or multiplication by zero and you get bogus results. This is a long-standing issue with the system.

You must set minimum window size to prevent that from happening.

Auto layout is the solution to that and many other limitations of the old model, for all of its flaws.

Ken Thomases
  • 88,520
  • 7
  • 116
  • 154
  • This makes sense. Let me try that! Thanks a lot! ;-) – Dr.Kameleon Dec 13 '14 at 08:52
  • Basically, here's what: when I revert to autoresizing masks, there's still one custom view that uses autolayout (programmatically). And after a while I keep getting errors in the console + the window doesn't seem resizeable at all... Very weird... – Dr.Kameleon Dec 13 '14 at 09:07
  • `Unable to simultaneously satisfy constraints: ( "", "", "", "" )` – Dr.Kameleon Dec 13 '14 at 09:07
  • Since you're using auto layout (because any view in the window requires it), you have to be careful about constraints that interact with view whose `translatesAutoresizingMaskIntoConstraints` is true. `translatesAutoresizingMaskIntoConstraints` causes the generation of constraints which fully determine the view's size and position based on the last frame which was set and whatever superview resizing has happened since. Any additional constraints on that view are likely to trying to do something else to it, which will conflict. So, such views should usually not be included in constraints. – Ken Thomases Dec 13 '14 at 11:30
  • 1
    It looks like you're embedding your view in a split view which is using auto layout. The split view will apply constraints to your view to keep it in position. If your view is translating autoresizing into constraints that could be a problem. If this is the container view containing the three views you describe in your question, the container should have `translatesAutoresizingMaskIntoConstraints` disabled, while the three controls have it enabled (and should not have constraints to their container superview). – Ken Thomases Dec 13 '14 at 11:33