Why is it not possible anymore to resize NSWindow after setting up constraints?

Marc

After a custom segue and a custom presentation animator, I set up constraints of the presented view.

let views = ["view" : childVC.view]
let horizontalConstraints = NSLayoutConstraint.constraintsWithVisualFormat("H:|[view]|", options: [], metrics: nil, views: views)
let verticalConstraints = NSLayoutConstraint.constraintsWithVisualFormat("V:|[view]|", options: [], metrics: nil, views: views)
parentVC.view.addConstraints(horizontalConstraints)
parentVC.view.addConstraints(verticalConstraints)

When I print out the constraints of the parent/presenting viewcontroller's view, there are only these four constraints. Now I expect my subview to be as resizable as the NSWindow, but both aren't resizable anymore.

I also give the translatesAutoresizingMaskIntoConstraint = false a try, but I do not really understand it. Furthermore, it removes everything from the views.

So what I'm missing here?

Ken Thomases

It sounds like your view is not using auto layout internally. It is relying on the old springs-and-struts model. That's why when you turn off translatesAutoresizingMaskIntoConstraint it "removes everything". More likely, the view is collapsing to zero size because there are no constraints to hold its size and position anymore.

When translatesAutoresizingMaskIntoConstraint is on, constraints are generated to hold the view at the last frame that was explicitly set for it. If its superview resizes and if the superview autoresizes its subviews (which is the default), the view will get resized according to its autoresizingMask. But auto layout sort of doesn't know that will happen. The generated constraints keep the frame like it is until the superview changes.

But you've also added constraints between the window's content view and your view. Those constraints effectively prevent the window from resizing because the view's constraints don't allow the layout system to resize it. Only explicit changes to its frame will do that. You're sort of in a catch-22. The view would resize if its superview resized, but the superview can't resize because the view has inflexible constraints on it.

In general, when you're working with a view which has translatesAutoresizingMaskIntoConstraint left on, you are very restricted in what other constraints you can usefully apply to that view. You can't really use constraints that "push" on the view's frame or size. You can only loosely "hang" other views off of that view.

In any case, you need to adopt auto layout for your view or just don't set constraints between it and its superview. Instead rely on the autoresizing mechanism.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why adding constraints removes the ability to resize NSWindow?

From Dev

NSWindow resize indicator not visible

From Dev

Why is canImport() not called anymore after setDropTarget()?

From Dev

UITableView behind NavigationBar after setting constraints

From Dev

Swift umbrella header not updated anymore after setting it to another file

From Dev

After setting manually, computed property do not observe changes anymore

From Dev

anchor scroll with angular/ionic breaks layout and scrolling up is not possible anymore

From Dev

Why don't elements display inline-block again after a resize down and up in Chrome?

From Dev

Highcharts chart resize on window resize event after setting a specific size

From Dev

Highcharts chart resize on window resize event after setting a specific size

From Dev

Weird issue when setting up auto-layout constraints in code

From Dev

Why can't I resize a canvas using the layout constraints?

From Dev

Why ngClick doesn't work anymore after $compile?

From Dev

Setting NSWindow position in current screen

From Dev

Setting NSWindow position in current screen

From Dev

Embedding lots of views into a uiscrollview and have constraints match up? Is this possible?

From Dev

Embedding lots of views into a uiscrollview and have constraints match up? Is this possible?

From Dev

Is it possible to set up constraints and objects outside of the ViewController file?

From Dev

Why setting the key constraints on column removes "NOT NULL" from it (MySQL)?

From Dev

Setting up a controller property after the model hook

From Dev

Is it possible to debug GWT anymore?

From Dev

Resize Table Column when NSWindow resizes

From Dev

Resise NSWindow without showing resize button

From Dev

Resise NSWindow without showing resize button

From Dev

Why does WSO2 API Manager throw an error when trying to publish an API after setting up a new jks

From Dev

Adding Subviews/Constraints: Trying to understand WHY my subviews are not showing up

From Dev

responsive Google chart only shows up after first resize

From Dev

Why isn't it possible to change placement constraints in an upgrade?

From Dev

Is it possible to resize memory.dmp file after creation?

Related Related

  1. 1

    Why adding constraints removes the ability to resize NSWindow?

  2. 2

    NSWindow resize indicator not visible

  3. 3

    Why is canImport() not called anymore after setDropTarget()?

  4. 4

    UITableView behind NavigationBar after setting constraints

  5. 5

    Swift umbrella header not updated anymore after setting it to another file

  6. 6

    After setting manually, computed property do not observe changes anymore

  7. 7

    anchor scroll with angular/ionic breaks layout and scrolling up is not possible anymore

  8. 8

    Why don't elements display inline-block again after a resize down and up in Chrome?

  9. 9

    Highcharts chart resize on window resize event after setting a specific size

  10. 10

    Highcharts chart resize on window resize event after setting a specific size

  11. 11

    Weird issue when setting up auto-layout constraints in code

  12. 12

    Why can't I resize a canvas using the layout constraints?

  13. 13

    Why ngClick doesn't work anymore after $compile?

  14. 14

    Setting NSWindow position in current screen

  15. 15

    Setting NSWindow position in current screen

  16. 16

    Embedding lots of views into a uiscrollview and have constraints match up? Is this possible?

  17. 17

    Embedding lots of views into a uiscrollview and have constraints match up? Is this possible?

  18. 18

    Is it possible to set up constraints and objects outside of the ViewController file?

  19. 19

    Why setting the key constraints on column removes "NOT NULL" from it (MySQL)?

  20. 20

    Setting up a controller property after the model hook

  21. 21

    Is it possible to debug GWT anymore?

  22. 22

    Resize Table Column when NSWindow resizes

  23. 23

    Resise NSWindow without showing resize button

  24. 24

    Resise NSWindow without showing resize button

  25. 25

    Why does WSO2 API Manager throw an error when trying to publish an API after setting up a new jks

  26. 26

    Adding Subviews/Constraints: Trying to understand WHY my subviews are not showing up

  27. 27

    responsive Google chart only shows up after first resize

  28. 28

    Why isn't it possible to change placement constraints in an upgrade?

  29. 29

    Is it possible to resize memory.dmp file after creation?

HotTag

Archive